Yes, but that has nothing to do with creating a valid SQL statement. The textbox is provided by the user, so your code should verify that it contains valid data. You then take the validated text and store into one of the SQL Parameters which get passed in to he execution module. Do not assume that the user knows what he or she is doing and just accept whatever they type. Many times it will be wrong, mist-typed, not understanding what is required, etc.
Parameters don't "sanitize" or "escape" special characters. They pass parameters across completely separately from the command text, so that there is no way for the database engine to get confused and treat part of the parameter as part of the command.
i have Two Database in two different servers i want to join two tables fromthis two Databases
i have no relation between them but just a column wich contain information about the other database
Ex : Database1.dbo.informationCity contain a column named Specification and have this information:
i want to extract fromthis column just this number 3439 because with this number i can rely the other database
Ex : Database2.dbo.city contain a column named cityID : 3439
any body have an idea how to do that ?
i tried this Sql request but it did not work
INNER JOIN [Database2].[dbo].[city ] ON substring([Specification], CHARINDEX('GMS', [Specification ]) + 3,4) =
Your join seems to be confused about the table names. According to your question, your tables are:
But according to your query, the tables are:
mo.dbo.Database1(Completely different name)
Database2.dbo.[city ](Extra space at the end of the name)
There's also nothing in there that would suggest the databases are on different servers. If they are, you'd need to create a linked server on the server where this query will run pointing to the other server, and use the four part name of the table you're trying to query - [Linked Server Name].[Database Name].[Schema Name].[Table Name].
From .NET code, you could use a library such as ClosedXML[^] to create an Excel sheet containing the query results. (Previously, I would have recommended EPPlus, but that's no longer free for commercial use.)
Or you could write the results out to a CSV file, which Excel will be able to open. I like to use the CsvHelper[^] for reading and writing CSV files, but other libraries are available (eg: fastCSV[^]).
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
no, that wasn't a copy & paste, it was a misspelling here, when I actually do it from my c# app it returns the column names (found a function to easily present col names and row data, so the columns are correct), and one row of empty data, just like in DB Browser
Just out the blue today I started getting this error on my Dev PC.
Cannot open database "MyDb" requested by the login. The login failed.
Login failed for user 'MicrosoftAccount\my_ms_account'.
The account name is one of my Microsoft account names, and happens to be the one tied this PC's Windows 10. There IS NO SQL login with that name. There have been no DB structure changes. Today I've done typical CRUD operations via C# & Linq-To-SQL. And again, this just started this afternoon.
I Googled it and found this. I'm hesitant to try that fix until I know what's happening. For now, if I log off and back on it seems to fix it, but then I have to close and reopen everything.
Anyone know what this is?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
Last Visit: 31-Dec-99 18:00 Last Update: 29-Sep-23 14:58