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);
}

Roei BarRank #1,271 · 1.4K reputationPosted Sep 24, 2009, 11:43 AM EDT
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
Nir Bar107 reputationPosted Sep 24, 2009, 11:46 AM EDT
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
aliya ahmed5 reputationPosted Sep 25, 2009, 12:20 AM EDT
aliya ahmed5 reputationPosted Sep 25, 2009, 12:30 AM EDT
Nir Bar107 reputationPosted Sep 25, 2009, 6:00 AM EDT
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