I am quite stuck. I have my database running on a seperate machine from where I am writing my application. The connection between Visual Studio and the database seems to be fine as I can display data in various controls on the GUI.
My problem arises when I try to add something to the database, I get no error messages just the data isn't added to the database.
Here is my code:
MyDataSet.categoryRow newRow = myDataSet.category.NewcategoryRow(); newRow.CategoryID = Convert.ToInt32(tbxID.Text); newRow.CategoryName = tbxCategory.Text; newRow.Description = tbxDescription.Text; myDataSet.category.Rows.Add(newRow); myDataSet.category.AcceptChanges(); categoryDA.Update(fYPDataSet); //categoryDA is the table adapter generated by visual studio
I have tried many variations on this in attempt to get it to work.
Including the following:
System.Data.SqlClient.SqlConnection con; System.Data.SqlClient.SqlDataAdapter da; con = new System.Data.SqlClient.SqlConnection(); con.ConnectionString = "Data Source=FYPSERVER;Initial Catalog=FYP;Integrated Security=True"; con.Open(); string sql = "SELECT * from category"; da = new System.Data.SqlClient.SqlDataAdapter(sql, con); con.Close(); System.Data.SqlClient.SqlCommandBuilder cb; cb = new System.Data.SqlClient.SqlCommandBuilder(da); MyDataSet.categoryRow newRow = myDataSet.category.NewcategoryRow(); newRow = tbxCategory.Text; newRow = tbxDescription.Text; myDataSet.Tables["category"].Rows.Add(newRow); //fYPDataSet.category.Rows.Add(newRow); //fYPDataSet.category.AcceptChanges(); da.Update(myDataSet, "catagory");
I also added a dataGridView control and linked that to the deisred table, using the design window, not through code.
Even when I add, edit or remove any of the values none of it is happening to the actual database or when I close and re-open that particular form.
I apologise if there has been some disucssion of this before but I have been working on this one aspect for a week and I am beginning to loose the will to live. I have done a search for this issue but all the results I have come across are due to error messages.
I am writing this in Visual Studio 2010 ultimate and the database is running under SQL Server 2008 R2 Enterprise
Thank you very much