N
nasirmajor
dear all,
if anyone can help about inserting records into datagrid from
arraylist.
e.g i have a following sample,please anyone sujjest what can i change
in it to make it better
ArrayList MyArray = new ArrayList();
MyArray.Add("1");
MyArray.Add("2");
MyArray.Add("3");
MyArray.Add("4");
protected void cmdadd_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("user
id=sa;password=;Initial Catalog=jobsdb;Data
Source=localhost;Integrated Security=SSPI;");
string arrayvaluesforjobcode = "";
foreach (Object obj in MyArray)
{
for (int i = 0; i <= MyArray.Count; i++)
{
arrayvaluesforjobcode += obj.ToString();
string s = "insert into tbl_dummy(job_code,firstname)
values (@job_code,@firstname)";
SqlCommand co = new SqlCommand(s, conn);
co.Parameters.Add(new SqlParameter("@job_code",
SqlDbType.int, 4));
co.Parameters["@job_code"].Value =
arrayvaluesforjobcode;
co.Parameters.Add(new SqlParameter("@firstname",
SqlDbType.VarChar, 100));
co.Parameters["@firstname"].Value = txtfirstname.Text;
conn.Open();
try
{
co.ExecuteNonQuery();
}
catch (SqlException exp)
{
spanname.InnerHtml = exp.Message.ToString();
spanname.Style["color"] = "red";
spanname.Style["font-size"] = "12px";
}
finally
{
conn.Close();
}
}
}
}
insertion happen but with alot of data in the table.
think me dummy like my dummy table and please help me.
if you want to give your sample code, i will be thankful to you.
thanks in advance
if anyone can help about inserting records into datagrid from
arraylist.
e.g i have a following sample,please anyone sujjest what can i change
in it to make it better
ArrayList MyArray = new ArrayList();
MyArray.Add("1");
MyArray.Add("2");
MyArray.Add("3");
MyArray.Add("4");
protected void cmdadd_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("user
id=sa;password=;Initial Catalog=jobsdb;Data
Source=localhost;Integrated Security=SSPI;");
string arrayvaluesforjobcode = "";
foreach (Object obj in MyArray)
{
for (int i = 0; i <= MyArray.Count; i++)
{
arrayvaluesforjobcode += obj.ToString();
string s = "insert into tbl_dummy(job_code,firstname)
values (@job_code,@firstname)";
SqlCommand co = new SqlCommand(s, conn);
co.Parameters.Add(new SqlParameter("@job_code",
SqlDbType.int, 4));
co.Parameters["@job_code"].Value =
arrayvaluesforjobcode;
co.Parameters.Add(new SqlParameter("@firstname",
SqlDbType.VarChar, 100));
co.Parameters["@firstname"].Value = txtfirstname.Text;
conn.Open();
try
{
co.ExecuteNonQuery();
}
catch (SqlException exp)
{
spanname.InnerHtml = exp.Message.ToString();
spanname.Style["color"] = "red";
spanname.Style["font-size"] = "12px";
}
finally
{
conn.Close();
}
}
}
}
insertion happen but with alot of data in the table.
think me dummy like my dummy table and please help me.
if you want to give your sample code, i will be thankful to you.
thanks in advance