sqlcommand

Confused between SqlCommand & SqlDataAdapter

亡梦爱人 提交于 2019-12-03 06:24:26
everyone I am a student and new to .NET and specially MVC3 development but for one of my project I’ve to work over it and so going through the learning phase Issue and confusion I am facing is regarding DB-Connectivity, whast I leanree d regarding retrieving records from a database is something like this: //Method One: var conn = new SqlConnection(conString.ConnectionString); const string cmdString = "Select * FROM table"; var cmd = new SqlCommand(cmdString, conn); var mySqlDataAdapter = new SqlDataAdapter(cmd); mySqlDataAdapter = new SqlDataAdapter(cmd); mySqlDataAdapter.Fill(myDataSet,

SqlCommand.Cancel() causes a performance boost?

亡梦爱人 提交于 2019-12-03 06:13:42
I have seen this show up several places in code, never with an explanation, just a cryptic comment above it (Declaration and execution included for an idea of context. It's just a standard procedure of running a SqlCommand): //SqlCommand cmd = new SqlCommand(); //cmd.ExecuteReader(); //Read off the results //Cancel the command. This improves query time. cmd.Cancel (); Basically, after finishing a query, it goes back and cancels it, claiming some performance boost. I suppose you might get some memory back when it goes and frees up the XmlReader, but usually it's about to go out of scope anyways

Write utf-8 to a sql server Text field using ADO.Net and maintain the UTF-8 bytes

﹥>﹥吖頭↗ 提交于 2019-12-02 09:51:10
问题 I have some xml encoded as UTF-8 and I want to write this to a Text field in SQL Server. UTF-8 is byte compatible with Text so it should be able to do this and then read out the xml later still encoded as utf-8. However special characters such as ÄÅÖ, which are multi-byte in UTF-8 get changed on the way. I have code like this: byte[] myXML = ... SqlCommand _MyCommand = new SqlCommand(storeProcedureName, pmiDB.GetADOConnection()); _MyCommand.CommandType = CommandType.StoredProcedure;

Is it necessary to dispose SqlConnection as well as SqlCommand?

微笑、不失礼 提交于 2019-12-02 08:52:07
问题 Is it necessary to separately dispose of a SqlConnection as well as a SqlCommand? I'm doing some maintenance work on an application and found the following code: public void CallStoredProc(string storedProcName) { using (SqlCommand command = new SqlCommand(storedProcName, CreateConnection())) { command.CommandType = CommandType.StoredProcedure; command.Connection.Open(); // Additional code here. command.ExecuteNonQuery(); } } Will this clean up the SqlConnection properly, under normal

Is it necessary to dispose SqlConnection as well as SqlCommand?

北城以北 提交于 2019-12-02 07:12:48
Is it necessary to separately dispose of a SqlConnection as well as a SqlCommand? I'm doing some maintenance work on an application and found the following code: public void CallStoredProc(string storedProcName) { using (SqlCommand command = new SqlCommand(storedProcName, CreateConnection())) { command.CommandType = CommandType.StoredProcedure; command.Connection.Open(); // Additional code here. command.ExecuteNonQuery(); } } Will this clean up the SqlConnection properly, under normal circumstances as well as if there is an error? Or would we have to alter the code to something like: public

GROUP BY issue when SELECT to dataGridView from 2 tables

荒凉一梦 提交于 2019-12-02 05:31:37
问题 With little help of you I made this two QUERY . I posted pictures so you can see that in green squares are empty values which I would like to see and in red squares are values which I wouldnt like to display. Variable vyberradek inserts values for 'subkey' it is INT in DB but I pass it through string . So I will simplify: Now I can display all or a little, would you help me how to display the correct records? This first query does this: string sQuery = string.Format("SELECT zajsluz.akce

SQL Update Column By Adding A Number To Current Int

亡梦爱人 提交于 2019-12-02 03:46:09
问题 Simple enough, I can't figure out how to add (that's +) an integer from a textbox to the integer in the SQL Field. So for example, the SQL Field may have '10' in it and the textbox may have '5' in it. I want to add these numbers together to store '15' without having to download the SQL Table. The textbox that contains the integer to be added to the SQL integer is tranamount.Text and the SQL Column in the SQL Table is @ugpoints. Please note, without the '+' - which is in the below code and is

GROUP BY issue when SELECT to dataGridView from 2 tables

空扰寡人 提交于 2019-12-01 23:31:20
With little help of you I made this two QUERY . I posted pictures so you can see that in green squares are empty values which I would like to see and in red squares are values which I wouldnt like to display. Variable vyberradek inserts values for 'subkey' it is INT in DB but I pass it through string . So I will simplify: Now I can display all or a little, would you help me how to display the correct records? This first query does this: string sQuery = string.Format("SELECT zajsluz.akce,zajsluz.text,klisluz.pocet,klisluz.subkey,zajsluz.ID FROM zajsluz LEFT JOIN klisluz ON zajsluz.ID=klisluz

SqlCommand.Prepare method requires all parameters to have an explicitly set type

徘徊边缘 提交于 2019-12-01 19:12:11
I have the following snippet of code in my WCF web service that builds a set of where conditions according to the formatting of the values of a provided dictionary. public static Dictionary<string, string>[] VehicleSearch(Dictionary<string, string> searchParams, int maxResults) { string condition = ""; foreach (string key in searchParams.Keys) { //Split out the conditional in case multiple options have been set (i.e. SUB;OLDS;TOY) string[] parameters = searchParams[key].Split(';'); if (parameters.Length == 1) { //If a single condition (no choice list) check for wildcards and use a LIKE if

I'm getting an error in SQL command not properly ended

£可爱£侵袭症+ 提交于 2019-12-01 16:34:36
when I enter this INSERT INTO works_on (essn, pno, hours) values ('123456789', 1, 32.5), ('123456789', 2, 7.5), ('666884444', 3, 40.0), ('453453453', 1, 20.0), ('453453453', 2, 20.0), ('333445555', 2, 10.0), ('333445555', 3, 10.0), ('333445555', 10, 10.0), ('333445555', 20, 10.0), ('999887777', 30, 30.0), ('999887777', 10, 10.0), ('987987987', 10, 35.0), ('987987987', 30, 5.0), ('987654321', 30, 20.0), ('987654321', 20, 15.0), ('888665555', 20, 0); I get the follow error ORA-00933: SQL command not properly ended In Oracle, you can't specify multiple sets of values like this (I'm guessing that