Hey Everyone

I looked on this site but didnt find anything good enough to help me. I have a DataTable called dt.

it has 230 records in it and 16 colums. I now want to put that table in a table in ms access called weapons. I have never written to a database before. I have only ever read from one. so if someone could help me that would be great.

also i would like to know if the colums have to be the same names and stuff.

thanks,
cgcgames

Dear i think my following tutorial help you!!!!!
for insert or write data into access database

int save = 0;

            try
                {
            string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=AccessDatabaseName.mdb";
            OleDbConnection conn = new OleDbConnection(connstr);


            conn.Open();





            if (textBox1.Text !="" && textBox2.Text !="" && textBox3.Text !="" && textBox4.Text !="" && textBox5.Text !="" && textBox6.Text !="" && comboBox1.Text !="" && comboBox2.Text !="" && comboBox3.Text !="" && comboBox4.Text !="" && gender != null)
            {
                string strInsert = "INSERT INTO contacts VALUES (";
                strInsert += "'" + textBox1.Text + "',  ";
                strInsert += "'" + string.Concat(textBox3.Text, textBox2.Text) + "',  ";
                strInsert += "'" + string.Concat(textBox5.Text, textBox4.Text) + "',  ";
                strInsert += "'" + textBox6.Text + "',  ";
                strInsert += "'" + textBox7.Text + "',  ";
                strInsert += "'" + comboBox4.Text + "')";
                //MessageBox.Show(strInsert);
                cmd = new OleDbCommand(strInsert, conn);
                cmd.ExecuteNonQuery();
                conn.Close();
                MessageBox.Show("data saved");
                save = 1;
            }
            else
            {
                MessageBox.Show("ENTER THE VALUE OF ALL FIELDS");
            }
                }

            catch(Exception exp)
            {
                MessageBox.Show("THIS NAME IS ALREADY EXIST");
            }


            if (save == 1)
            {
//Data saved in access database

            }

um isnt there a way to eneter a table into a database?

nice idea :) i got it to work. i just loaded the datarow into the database by doing dr[g] runing a loop of 16 and then it would add all the values to the string which ended up loading the datarow to the database

@cgcgames Thanks

& that's cool you done it!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.