I am thinking if it is possible to insert multipe rows of Data in one shot?
The code I trying to use but cannot seen working,Data1 is the name of one list of input that can be insert by the user(List Box) :
String connect= "Provider=Microsoft.JET.OLEDB.4.0;"+@"data source=c:\Some.mdb";
OleDbConnection con= new OleDbConnection(connect);
con.Open();
OleDbCommand cmd =con.CreateCommand();
OleDbParameter Casep1;
for(int i=0;i { Data1.SelectedIndex=i; cmd.CommandText= "INSERT INTO Example VALUES(?)"; Casep1 = new OleDbParameter(); Casep2.Value=Data1.Text.Substring(0,10).Trim(); cmd.Parameters.Add(Casep1); cmd.ExecuteNonQuery(); } con.Close();
Posted Jul 21, 2005, 1:40 AM
try this .. assumed that u need only the first 10 characters of the list into the values and they are strings
for(int i=0;i
{
}
best of luck!
Andrzej WegierskiPosted Jul 15, 2005, 8:08 AM
killingseedPosted Jul 14, 2005, 8:08 PM
not sure this will help but i'll give it a shot, i have to update one column from a bunch rows , i had threaded the function for a better stream of the update, i did a select on the data drop it in a grid "for viewing only"
then updated the dataset back to the database. as you be able to tell i have it do some clean to the SSN column that users felt they could put anything in that column (grrr users)
private void updatedata()
{
DataTable table = myDataSet.Tables[0];
int iColCount = table.Columns.Count;
int countNull = 0;// used during the thread to watch it count all the user misstaked
this.label1.Text = countNull.ToString();
for(int j = 0; j < table.Rows.Count; j++)
{
for (int i = 0; i < iColCount; i++)
{
if(i==3)
{
if(table.Rows[j].ItemArray[i].ToString()=="--"
||table.Rows[j].ItemArray[i].ToString()=="000-00-0000"
||table.Rows[j].ItemArray[i].ToString()=="n/a"
||table.Rows[j].ItemArray[i].ToString()=="N/A"
||table.Rows[j].ItemArray[i].ToString()==null
||table.Rows[j].ItemArray[i].ToString()=="0"
||table.Rows[j].ItemArray[i].ToString()=="No Answer"
||table.Rows[j].ItemArray[i].ToString()=="NO answer"
||table.Rows[j].ItemArray[i].ToString()=="No answer"
||table.Rows[j].ItemArray[i].ToString()=="00000000000"
||table.Rows[j].ItemArray[i].ToString()=="0000000000000"
||table.Rows[j].ItemArray[i].ToString()=="000000000"
||table.Rows[j].ItemArray[i].ToString()=="0000000000"
||table.Rows[j].ItemArray[i].ToString()=="999-99-9990"
||table.Rows[j].ItemArray[i].ToString()=="999-99-9911")
{
Updatenames(table.Rows[j].ItemArray[0].ToString());
countNull++;
}
//MessageBox.Show(table.Rows[j].ItemArray[i].ToString());
}
}
this.label1.Text = countNull.ToString();
}
MessageBox.Show("Task Completed!");
}
private void Updatenames(string RowID)
{
try
{
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+textBox1.Text+"; User Id=;Password=;" ;
OleDbConnection conn = new OleDbConnection(connectionString);
OleDbCommand oleDBpar;
string q="UPDATE [Client Table] SET "
+ "SSN=@SSN"
+" WHERE [Client Table].ID='"+RowID+"';";
oleDBpar= new OleDbCommand(q, conn);
oleDBpar.Parameters.Add(new OleDbParameter("@SSN", OleDbType.VarWChar,50));
oleDBpar.Parameters["@SSN"].Value = "";
oleDBpar.Connection.Open();
oleDBpar.ExecuteNonQuery();
oleDBpar.Connection.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}