In c# .net
Can some guide importing whats in my datagridview right into MS Access 2007.
I want to be able to point to the .mdb file that I want or just simply import to MS Access 2007
can some one guide me,
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sam HobbsRank #107 · 20.5K reputationPosted Feb 23, 2010, 5:18 PM EST
See Visual C++ Guided Tour for a worthwhile tour, except you don't need to do them in the order they appear.
kiran kumarRank #3,110 · 461 reputationPosted Feb 23, 2010, 5:30 PM EST
here is the screen shots of my sample project.
you can add rows dynamically.enter the no of rows in the textbox to be added in the datagrid and click on the button "add rows",after doing this enter the values in datagrid and click on the button "save to access database" and a window appears informing you that your values were saved to access database
PLEASE MARK THE ANSWER IF IT HELPS YOU
David SmithRank #999 · 2K reputationPosted Feb 24, 2010, 11:59 AM EST
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\z1083774\\Desktop\\CIF CCA UTILITY\\Working Project CIF\\Software Info\\CifCLUOpDataLibrary\\WindowsFormsApplication1\\bin\\Debug\\CLU_OpData.mdb";
objConnection = new OleDbConnection(strConnection);
objConnection.ConnectionString = strConnection;
objConnection.Open();
OleDbCommand cmd = new OleDbCommand("insert into
CLU_OpData(Index,Op_Time_Stamp,UUT_MSN,OperationID,Etag,EDescription,E_Time_Stamp1,E_Time_Stamp2,EValue)values(@Index,@Op_Time_Stamp,@UUT_MSN,@OperationID,@Etag,@EDescription,@E_Time_Stamp1,@E_Time_Stamp2,@EValue)", objConnection);
for (int i = 0; i < dataGridView2.RowCount; i++)
{
OleDbParameter odbpIndex = new OleDbParameter("@Index", OleDbType.VarChar, 50);
odbpIndex.Value = this.dataGridView2.Rows[i].Cells[0].Value.ToString();
cmd.Parameters.Add(odbpIndex);
OleDbParameter odbpOpTimeStamp = new OleDbParameter("@Op_Time_Stamp", OleDbType.VarChar, 50);
odbpOpTimeStamp.Value = dataGridView2.Rows[i].Cells[1].Value.ToString();
cmd.Parameters.Add(odbpOpTimeStamp);
OleDbParameter odbpUutMsn = new OleDbParameter("@UUT_MSN", OleDbType.VarChar, 50);
odbpUutMsn.Value = dataGridView2.Rows[i].Cells[2].Value.ToString();
cmd.Parameters.Add(odbpUutMsn);
OleDbParameter odbpOperationID = new OleDbParameter("@OperationID", OleDbType.VarChar, 50);
odbpOperationID.Value = this.dataGridView2.Rows[i].Cells[3].Value.ToString();
cmd.Parameters.Add(odbpOperationID);
OleDbParameter odbpEtag = new OleDbParameter("@Etag", OleDbType.VarChar, 50);
odbpEtag.Value = dataGridView2.Rows[i].Cells[4].Value.ToString();
cmd.Parameters.Add(odbpEtag);
OleDbParameter odbpEDescription = new OleDbParameter("@EDescription", OleDbType.VarChar, 50);
odbpEDescription.Value = this.dataGridView2.Rows[i].Cells[5].Value.ToString();
cmd.Parameters.Add(odbpEDescription);
OleDbParameter odbpEtimeStamp1 = new OleDbParameter("@E_Time_Stamp1", OleDbType.VarChar, 50);
odbpEtimeStamp1.Value = dataGridView2.Rows[i].Cells[6].Value.ToString();
cmd.Parameters.Add(odbpEtimeStamp1);
OleDbParameter odbpEtimeStamp2 = new OleDbParameter("@E_Time_Stamp2", OleDbType.VarChar, 50);
odbpEtimeStamp2.Value = this.dataGridView2.Rows[i].Cells[7].Value.ToString();
cmd.Parameters.Add(odbpEtimeStamp2);
OleDbParameter odbpEvalue = new OleDbParameter("@EValue", OleDbType.VarChar, 50);
odbpEvalue.Value = this.dataGridView2.Rows[i].Cells[8].Value.ToString();
cmd.Parameters.Add(odbpEvalue);
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
kiran kumarRank #3,110 · 461 reputationPosted Feb 24, 2010, 3:31 PM EST
kiran kumarRank #3,110 · 461 reputationPosted Feb 24, 2010, 6:22 PM EST
hope it resolves your problem
mark the answer if it helps you
David SmithRank #999 · 2K reputationPosted Feb 24, 2010, 6:33 PM EST
what do you mean try adding rows dynamically?
David SmithRank #999 · 2K reputationPosted Feb 24, 2010, 7:09 PM EST
David SmithRank #999 · 2K reputationPosted Feb 24, 2010, 7:57 PM EST
David SmithRank #999 · 2K reputationPosted Feb 24, 2010, 8:50 PM EST
Also karan if my column headers in access are int , datetime, text, text , text, text, text, text does thats matter in code.
meaning the OleDbType.VarChar, 50.
should it be this way
OleDbType.Interger, 50
OleDbType.DBDatetime, 50
OleDbType.VarChar, 50
OleDbType.VarChar, 50
OleDbType.VarChar, 50
OleDbType.VarChar, 50
OleDbType.VarChar, 50
OleDbType.VarChar, 50
kiran kumarRank #3,110 · 461 reputationPosted Feb 24, 2010, 9:22 PM EST
kiran kumarRank #3,110 · 461 reputationPosted Feb 24, 2010, 9:25 PM EST
David SmithRank #999 · 2K reputationPosted Feb 24, 2010, 9:53 PM EST
the properties are
int Index
datetime Op_Time_Stamp
text UUT_MSN
text OperationID
text Etag
text EDescription
text E_Time_Stamp1
text E_Time_Stamp2
text EValue
I think it fails at the datetime property im not for sure, I have 916 rows in the datatable right now, so I didnt step through all of the rows
but
kiran kumarRank #3,110 · 461 reputationPosted Feb 24, 2010, 10:10 PM EST
why you go for varchar,take the datatype as datetime
mark the answer if it helps you
kiran kumarRank #3,110 · 461 reputationPosted Feb 24, 2010, 10:13 PM EST
MARK THE ANSWER IF IT HELPS YOU
David SmithRank #999 · 2K reputationPosted Feb 24, 2010, 10:15 PM EST
also do I use integer for the OleDbTpyr for the int column, I tried all of this, let me make sure, did you get my project
kiran kumarRank #3,110 · 461 reputationPosted Feb 24, 2010, 10:16 PM EST
mark the answer if it helps you
David SmithRank #999 · 2K reputationPosted Feb 24, 2010, 10:19 PM EST
David SmithRank #999 · 2K reputationPosted Feb 24, 2010, 10:19 PM EST
kiran kumarRank #3,110 · 461 reputationPosted Feb 24, 2010, 10:50 PM EST
David SmithRank #999 · 2K reputationPosted Feb 25, 2010, 5:02 AM EST
kiran kumarRank #3,110 · 461 reputationPosted Feb 25, 2010, 5:14 AM EST
David SmithRank #999 · 2K reputationPosted Feb 25, 2010, 5:52 AM EST
David SmithRank #999 · 2K reputationPosted Feb 25, 2010, 3:51 PM EST
David SmithRank #999 · 2K reputationPosted Feb 26, 2010, 9:29 AM EST
alot of people dont know. So be careful guys . I change Index to CIfIndex and it work perfectly find.
But I after the program finish update its get a error saying object reference is not set to an instance of an object. I think thats a null issue, how can i advoid that.