sqldatareader

How to resolve an IndexOutOfRangeException on bit value?

送分小仙女□ 提交于 2020-01-07 00:04:07
问题 I'm reading back a bit value from an SQL table, and casting as a boolean value to map to a boolean model value. But when I read back the IsPDLChecked bit field and initialise as false, I get an index out of range exception . I looked up the definition of the exception and I'm not sure why the value is out of range due to it being init with a false value , ie, 0 . So it's not a negative range value. Question: Why am I getting an IndexOutOfRange exception although the bit value being read back

SQL Data Reader: Invalid attempt to read when no data is present

。_饼干妹妹 提交于 2020-01-03 03:31:08
问题 I am trying to use a SqlDataReader to run a query and then display the results in a messagebox, but I keep getting the error Invalid attempt to read when no data is present. Here is my code. public void button1_Click(object sender, EventArgs e) { string results = ""; using (SqlConnection cs = new SqlConnection(@"Server=100-nurex-x-001.acds.net;Database=Report;User Id=reports;Password=mypassword")) { cs.Open(); string query = "select stationipaddress from station where stationname = @name";

Is there any performance gain from CommandBehavior.SequentialAccess?

大憨熊 提交于 2020-01-01 08:41:52
问题 I realized I always read my fields in the order they are returned by index (using constants). So my code is already compatible with CommandBehavior.SequentialAccess as far as i understand. Would there be any benefits if i turn it on? DataReader is already forward only, read only which is the real performance gain right? 回答1: The main usage of this is when you are reading very large CLOB ( nvarchar(max) etc) or BLOB ( varbinary(max) ) fields. In the default usage, it buffers the entire row of

Is there any performance gain from CommandBehavior.SequentialAccess?

吃可爱长大的小学妹 提交于 2020-01-01 08:41:04
问题 I realized I always read my fields in the order they are returned by index (using constants). So my code is already compatible with CommandBehavior.SequentialAccess as far as i understand. Would there be any benefits if i turn it on? DataReader is already forward only, read only which is the real performance gain right? 回答1: The main usage of this is when you are reading very large CLOB ( nvarchar(max) etc) or BLOB ( varbinary(max) ) fields. In the default usage, it buffers the entire row of

How can I get return value of stored procedure when using SqlDataReader?

扶醉桌前 提交于 2020-01-01 03:10:08
问题 Is it not possible to get the return value of a stored procedeure when using a datareader? The return value is always null, but the SP returns a valid int from within SSMS. myCommand.CommandText = "GetVenueVideos"; SqlParameter retVal = new SqlParameter("@returnValue",SqlDbType.Int); retVal.Direction = ParameterDirection.ReturnValue; myCommand.Parameters.Add(retVal); myReader = myCommand.ExecuteReader(); if (myReader.Read() && myReader.HasRows) { int returnValue = Convert.ToInt32(retVal.Value

SqlDataReader parameter not working

风格不统一 提交于 2019-12-31 07:42:48
问题 I have a windows form that I am asking a user to enter a pcname in textbox1 and then trying to use SqlDataReader to the read from the database to get the pc ipaddress and then map the pc drive to my local pc. But for some reason when I use the textbox within the SQL parameter it's not working. But when I replace the textbox1.text with the actual pcname it works fine. Hopefully someone can help me find out why the parameter isn't working correctly. Here is my code: public void button1_Click

Handle NULL in Datareader

天大地大妈咪最大 提交于 2019-12-31 03:58:11
问题 This is the code I' using for reading data from sql through DataReader. It gives Error when there is a NULL in table. How to handle it? I tried c.ActualWeight= dr[0] as float? ?? default(float); The problem with this is that it is successful in Handling NULLs but the result is Always 0 even if the sql database has value 1 in that field. { List<Inventory_Connector> LC = new List<Inventory_Connector>(); string ConString = "data source=DELL\\SQLSERVER1;Initial Catalog=Camo;Integrated Security

Why use the GetOrdinal() Method of the SqlDataReader

白昼怎懂夜的黑 提交于 2019-12-29 05:53:07
问题 What's the difference between reading a value from an SqlDataReader using this syntax: Dim reader As SqlClient.SqlDataReader reader("value").ToString() OR Dim reader As SqlClient.SqlDataReader reader.GetString(reader.GetOrdinal("value")) 回答1: I think that the reason to use GetOrdinal() is so that you can cache the result and re-use it multiple times for performance. E.g. Dim reader As SqlClient.SqlDataReader int valueOrdinal = reader.GetOrdinal("value"); while ( ... ) { var value = reader

How do I get values from a SQL database into textboxes using C#?

我只是一个虾纸丫 提交于 2019-12-28 16:25:08
问题 I'm creating a booking management system and I am having problems trying to get data from a SQL database and insert into a group of textboxes of my application. I want to show the customer details, when a button is clicked, in a DataGridView, but when I click the button, the application throws an exception with the following error message; Invalid attempt to read when no data is present. I have attached a screenshot of the screen where I want to view customer details, and the code for the

How do I get values from a SQL database into textboxes using C#?

痴心易碎 提交于 2019-12-28 16:25:06
问题 I'm creating a booking management system and I am having problems trying to get data from a SQL database and insert into a group of textboxes of my application. I want to show the customer details, when a button is clicked, in a DataGridView, but when I click the button, the application throws an exception with the following error message; Invalid attempt to read when no data is present. I have attached a screenshot of the screen where I want to view customer details, and the code for the