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;

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";


string sql = "SELECT * from category";
da = new System.Data.SqlClient.SqlDataAdapter(sql, con);

System.Data.SqlClient.SqlCommandBuilder cb;
cb = new System.Data.SqlClient.SqlCommandBuilder(da);
MyDataSet.categoryRow newRow = myDataSet.category.NewcategoryRow();

newRow[1] = tbxCategory.Text;
newRow[2] = tbxDescription.Text;

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

6 Years
Discussion Span
Last Post by prvnkmr194

Here is my simple code to save the record in table.

cnn.ConnectionString = "your connection string";
cmd.CommandText = "select * from <tablename>";
cmd.Connection = cnn;
da.SelectCommand = cmd;
da.Fill(ds, "<tablename>");

OleDbCommandBuilder cmb = new OleDbCommandBuilder(da);
DataRow drow;
drow = ds.Tables["table1"].NewRow();

drow["column1"] = textBox1.Text;
drow["column2"] = textBox2.Text;
drow["column3"] = textBox3.Text;

da.Update(ds, "table1");
MessageBox.Show("ONE RECORD IS ADDED.");

ds dataset
da data adapter
table1 name of your table
column1,column2.column3 is the name of column in your table
cmd is a command object

I hope it will help you other wise feel free to ask any problem

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.