executereader

C# Invalid attempt to call Read when reader is closed

只谈情不闲聊 提交于 2019-11-30 06:50:49
I am having Invalid attempt to call Read when reader is closed error when I am doing 3 tier project in C# language. What I am trying to do is retrieve address data column by joining two tables together and display in a drop down list. Here is my data access layer: public List<Distribution> getDistributionAll() { List<Distribution> distributionAll = new List<Distribution>(); string address; SqlDataReader dr = FoodBankDB.executeReader("SELECT b.addressLineOne FROM dbo.Beneficiaries b INNER JOIN dbo.Distributions d ON d.beneficiary = b.id"); while (dr.Read()) { address = dr["addressLineOne"]

An OLE DB Provider was not specified in the ConnectionString. 'Provider=SQLOLEDB;

做~自己de王妃 提交于 2019-11-29 14:42:12
i trying to run query using C#, i am getting the following problem An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB; my code string strConString = System.Configuration.ConfigurationManager.ConnectionStrings["WorkflowConnStr"].ConnectionString.ToString(); string sqlstr = "select * from table" OleDbConnection myConnection = new OleDbConnection(strConString); try {myConnection.Open();} catch (Exception err) { System.Diagnostics.Debug.WriteLine(err.Message); } OleDbCommand myCommand = new OleDbCommand(sqlstr, myConnection); OleDbDataReader

Invalid attempt to call FieldCount when reader is closed

余生长醉 提交于 2019-11-29 12:34:15
The error above occurs when I try to do a dataReader.Read on the data recieved from the database. I know there are two rows in there so it isnt because no data actually exists. Could it be the CommandBehavior.CloseConnection, causing the problem? I was told you had to do this right after a ExecuteReader? Is this correct? try { _connection.Open(); using (_connection) { SqlCommand command = new SqlCommand("SELECT * FROM Structure", _connection); SqlDataReader dataReader = command.ExecuteReader(CommandBehavior.CloseConnection); if (dataReader == null) return null; var newData = new List<Structure

Invalid attempt to call FieldCount when reader is closed

纵然是瞬间 提交于 2019-11-28 06:10:24
问题 The error above occurs when I try to do a dataReader.Read on the data recieved from the database. I know there are two rows in there so it isnt because no data actually exists. Could it be the CommandBehavior.CloseConnection, causing the problem? I was told you had to do this right after a ExecuteReader? Is this correct? try { _connection.Open(); using (_connection) { SqlCommand command = new SqlCommand("SELECT * FROM Structure", _connection); SqlDataReader dataReader = command.ExecuteReader

SqlCommand INSERT INTO query does not execute

人走茶凉 提交于 2019-11-28 02:26:01
Hello guys I have got this code: SqlCommand scom = new SqlCommand( "INSERT INTO klient(name,surname) values(@kname,@ksurname)", conn); scom.Parameters.AddWithValue("@kname", kname.Text); scom.Parameters.AddWithValue("@ksurname", ksurname.Text); conn.Open(); DataTable dt = new DataTable(); SqlDataAdapter SDA = new SqlDataAdapter("SELECT * FROM klient", spojeni); SDA.Fill(dt); conn.Close(); It should insert data from textboxes: kname, ksurname, but it closes the form without showing them in MS SQL table klient Missing the ExecuteNonQuery call SqlCommand prikaz = new SqlCommand("INSERT INTO

SqlCommand INSERT INTO query does not execute

╄→尐↘猪︶ㄣ 提交于 2019-11-26 23:43:38
问题 Hello guys I have got this code: SqlCommand scom = new SqlCommand( "INSERT INTO klient(name,surname) values(@kname,@ksurname)", conn); scom.Parameters.AddWithValue("@kname", kname.Text); scom.Parameters.AddWithValue("@ksurname", ksurname.Text); conn.Open(); DataTable dt = new DataTable(); SqlDataAdapter SDA = new SqlDataAdapter("SELECT * FROM klient", spojeni); SDA.Fill(dt); conn.Close(); It should insert data from textboxes: kname, ksurname, but it closes the form without showing them in MS