sqldataadapter

populating a list view with sql database items

大憨熊 提交于 2019-12-04 19:02:46
My application is based on displaying a dialog box when the user enters the "add category" button. It then should save data into an SQL Database and populate a list view with each item the user adds. I chose SQL database because I want the data to be saved when the user ends the app. How do I actually populate the list view with those items ? Here is what I have so far: public class CategoryDatabase { public static final String KEY_ROWID = "_id"; public static final String KEY_CATEGORY = "category"; private static final String DATABASE_NAME = "DBCategory"; private static final String DATABASE

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,

SqlDataAdapter.Fill(DataGridView.DataSource) duplicates all rows

纵然是瞬间 提交于 2019-12-02 13:20:25
Simple question: When I call SqlDataAdapter.Fill(DataGridView.DataSource) the second time after initially creating first Data it does not update the contained rows. It simply adds all rows returned by the select command to my DataGridView. If I call it a third, fourth (so on) it will also just add the returned rows. Am I understanding the .Fill(DataTable) function wrong? How do I update the already existing DataTable correctly? Which line of code is responsible for that? Turns out it has to be a code problem; DataGridView1.AutoGenerateColumns = False Dim sql = "select * from myTable" oDtSource

Object must implement IConvertible

泪湿孤枕 提交于 2019-12-02 12:19:39
问题 Object must implement IConvertible. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Object must implement IConvertible. Error Detail Line 279: da.InsertCommand.Parameters.Add("@Total", SqlDbType.Int).Value = txttotal.Text; Line 280: con1.Open(); Line 281: da.InsertCommand.ExecuteNonQuery(); Code:

Why won't this DataAdapter insert rows into the database?

别等时光非礼了梦想. 提交于 2019-12-02 03:07:56
问题 So I have a situation where I am using a SqlDataAdapter to insert rows into a table in a SQL Server 2014 database. The source of the data is an Excel spreadsheet. The insert works fine when the DataTable object is populated using a few For loops and .Columns.Add and .Rows.Add to copy the data from the Excel sheet. This working code I have not included here. However, I am refactoring the code to use an OleDbDataReader. Here is my function: Private Function FillDataTable(path As String, name As

Why won't this DataAdapter insert rows into the database?

限于喜欢 提交于 2019-12-02 01:16:45
So I have a situation where I am using a SqlDataAdapter to insert rows into a table in a SQL Server 2014 database. The source of the data is an Excel spreadsheet. The insert works fine when the DataTable object is populated using a few For loops and .Columns.Add and .Rows.Add to copy the data from the Excel sheet. This working code I have not included here. However, I am refactoring the code to use an OleDbDataReader. Here is my function: Private Function FillDataTable(path As String, name As String) As DataTable Dim fullpath As String = path Dim wsname As String = name Dim dt = New DataTable(

SqlDataAdapter with using keyword

偶尔善良 提交于 2019-12-01 20:25:48
问题 Is this the following code healthy? Or I don't need to use the using keyword as the SqlDataAdapter will handle closing the connection? public static DataSet Fetch(string sp, SqlParameter [] prm) { using (SqlConnection con = new SqlConnection(ConStr)) { using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = sp; cmd.Parameters.AddRange(prm); using (SqlDataAdapter dta = new SqlDataAdapter(cmd)) { DataSet dst = new DataSet(); dta.Fill(dst);

SqlDataAdapter with using keyword

大城市里の小女人 提交于 2019-12-01 19:14:11
Is this the following code healthy? Or I don't need to use the using keyword as the SqlDataAdapter will handle closing the connection? public static DataSet Fetch(string sp, SqlParameter [] prm) { using (SqlConnection con = new SqlConnection(ConStr)) { using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = sp; cmd.Parameters.AddRange(prm); using (SqlDataAdapter dta = new SqlDataAdapter(cmd)) { DataSet dst = new DataSet(); dta.Fill(dst); return dst; } } } } @MarkGravell I need a suggestions here, I am really looking to use DataReader ,

How bad is opening and closing a SQL connection for several times? What is the exact effect?

北慕城南 提交于 2019-12-01 08:38:43
For example, I need to fill lots of DataTables with SQLDataAdapter's Fill() method: DataAdapter1.Fill(DataTable1); DataAdapter2.Fill(DataTable2); DataAdapter3.Fill(DataTable3); DataAdapter4.Fill(DataTable4); DataAdapter5.Fill(DataTable5); .... .... Even all the dataadapter objects use the same SQLConnection, each Fill method will open and close the connection unless the connection state is already open before the method call. What I want to know is how does unnecessarily opening and closing SQLConnections affect the performance of the application. How much does it need to scale to see the bad

How bad is opening and closing a SQL connection for several times? What is the exact effect?

匆匆过客 提交于 2019-12-01 07:20:47
问题 For example, I need to fill lots of DataTables with SQLDataAdapter's Fill() method: DataAdapter1.Fill(DataTable1); DataAdapter2.Fill(DataTable2); DataAdapter3.Fill(DataTable3); DataAdapter4.Fill(DataTable4); DataAdapter5.Fill(DataTable5); .... .... Even all the dataadapter objects use the same SQLConnection, each Fill method will open and close the connection unless the connection state is already open before the method call. What I want to know is how does unnecessarily opening and closing