how to generalize SQL queries
-
I'm doing some database in C# using MS SQL. Problem #1: Everytime i do a connection to my database, i have to copy and paste the code over and over. I heard of a way to put these code in the configuration file, but i don't know how to. Problem #2: I also heard of someway(interface, object) allowing me to do SQL query indirectly instead of passing the query string directly into the SqlCommand object. And, again, I don't know how to. Problem #3: Is there anyway i can pass in my sql query dynamically(ie, as a varible)? I just learn C# on my own, and having problem searching for things like this Please help me out! THANKS A BUNCH!!!
-
I'm doing some database in C# using MS SQL. Problem #1: Everytime i do a connection to my database, i have to copy and paste the code over and over. I heard of a way to put these code in the configuration file, but i don't know how to. Problem #2: I also heard of someway(interface, object) allowing me to do SQL query indirectly instead of passing the query string directly into the SqlCommand object. And, again, I don't know how to. Problem #3: Is there anyway i can pass in my sql query dynamically(ie, as a varible)? I just learn C# on my own, and having problem searching for things like this Please help me out! THANKS A BUNCH!!!
puppiesLover wrote: Problem #1: Everytime i do a connection to my database, i have to copy and paste the code over and over. I heard of a way to put these code in the configuration file, but i don't know how to. Depends on the type of database connector you're using, I guess. If you drop an SQL data connection onto a form, the IDE will automatically generate the code for it. If the generated connection string is not what is needed, I'll put code in the constructor to overwrite it. Be sure to place this code after the InitialComponents method call. >>>-----> MikeO