data not inserted in sql database
hi!
I am trying to insert data from textboxes in sql server 2005 database using dataset(table adapters) in c# windows application
I have made two tables in my database i.e. product and country table.
In country table adapter i add query of insert and execute there and its working correctly but when i m using textboxes to insert data in tables, it not works and even not giving any errors or exceptions.
plz help me out!
herez the code,
private void button1_Click(object sender, EventArgs e)
{
DataSet1TableAdapters.countryTableAdapter cta = new WindowsApplication4.DataSet1TableAdapters.countryTableAdapter();
DataSet1.countryDataTable ctbl = new DataSet1.countryDataTable();
cta.Insertdata(textBox1.Text, textBox2.Text);
}
Nir BarPosted Sep 25, 2009, 10:00 AM
I don't know of any other way except the DataTable-DataRow-DataAdapter method.
In the code that you pasted in your first post I don't see a call to DataAdapter.Update
This method stores new rows in the SQL database
Please mark this post as an answer if it helps you
Nir
aliya ahmedPosted Sep 25, 2009, 4:30 AM
aliya ahmedPosted Sep 25, 2009, 4:20 AM
Nir BarPosted Sep 24, 2009, 3:46 PM
I think you need to learn the basics of working with DataSet and DataTable
There's documentation here
In general:
SQL tables are represented in DataTable objects
SQL table rows are represented in DataRow
Hence to populate data in SQL table, you add rows (DataRow) to DataTable
TableAdapter then helps in loading SQL table into DataTable, and vice-versa
Please mark this post as an answer if it helps you
Nir
Roei BarPosted Sep 24, 2009, 3:43 PM
in order to make SQL get Date Format
go into sql type getdate
then do the following
DateTime dt = DateTime.Now();
dt.ParseExact(TextBox1.Text);
on the Insert command make sure to write the dt.ToString("yyyy-MM-dd HH:mm:ss")
if i am not mistaken this is the format but you can make sure by the getdate format