Hi. I create the table (MS SQL 2008)


IdUrovniaKatHerakl - HierarchyId (not null primary key),
KatName nvarchar(max) not null,
LevelKat as RowId.GetLevel()
KatId - int
KatOpisanie nvarchar(max)

How can I using C# in Visual Studio 2010 (RC) insert new data into this table?

I do this: create DataSet and Create TableAdapter for this table

DataSet1 ds = new DataSet1();
   DataSet1TableAdapters.KategoriiFotoTableAdapter kategoriiFotoTableAdapter = new DataSet1TableAdapters.KategoriiFotoTableAdapter();
    DataSet1.KategoriiFotoRow newKategoriiFotoRow = ds.KategoriiFoto.NewKategoriiFotoRow();
         SqlHierarchyId her;
          SqlHierarchyId gt =  SqlHierarchyId.Null;

          newKategoriiFotoRow.IdUrovniaKatHerakl = (her.GetDescendant(gt,null));
           newKategoriiFotoRow.KatName = TextBox1.Text;
    newKategoriiFotoRow.KatOpisanie = "'eto opisanie";
        
    ds.KategoriiFoto.Rows.Add(newKategoriiFotoRow);

    kategoriiFotoTableAdapter.Update(ds.KategoriiFoto);

But it does not work, eror in "newKategoriiFotoRow.IdUrovniaKatHerakl = (her.GetDescendant(gt,null));"
help me. Roman

Recommended Answers

All 2 Replies

Please read the rules before posting again - We strive to be a community geared towards the professional. We strongly encourage all posts to be in full-sentence English.

>How can I using C# in Visual Studio 2010 (RC) insert new data into this table?

SqlConnection cn=new SqlConnection("put_connection_string");
SqlCommand cmd=new SqlCommand("insert into table (col1,col2) values (@col1,@col2)");

cmd.Parameters.AddWithValue("@col1",value1);
cmd.Parameters.AddWithValue("@col2",value2);

cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
..

Many thanks for your recommendations and the help. It has very much helped me to resolve the given problem.
Excuse for my errors.

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.