inserting record with arraylist

Discussion in 'ASP .Net' started by nasirmajor@yahoo.com, Jun 22, 2006.

  1. Guest

    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
    , Jun 22, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Saravanan Rathinavelu

    Iterate through ArrayList using an another ArrayList

    Saravanan Rathinavelu, Aug 16, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,729
    Natty Gur
    Aug 19, 2003
  2. Kaidi
    Replies:
    4
    Views:
    2,335
    Kaidi
    Jan 3, 2004
  3. Replies:
    1
    Views:
    396
    Hans Kesting
    Jun 22, 2006
  4. xz
    Replies:
    16
    Views:
    2,346
  5. Philipp
    Replies:
    6
    Views:
    904
    Arne Vajhøj
    May 28, 2008
Loading...

Share This Page