Skip to content

Select () certain Row from Table in Database to XML file

Bondari Developers

Asked Feb 3, 2016, 10:23 PM EST4 answers
Share
LinkedInX
Hello C# Corner ,
 
 I want to select only one row from table and  save that data of the only selsected row in xml file,
That row i want its information will be (TextBox.Text). Any information will be in the textbox it will save data to xml file.
 
this is my Code:
C#
 ConnectionString = @"Data Source=LocalDB\SQLEXPRESS;Initial Catalog=TestDB;Integrated Security=True";
                    connection = new SqlConnection(ConnectionString);
                    sql = "Select * from Table_Sub where  ActivationCode = "" "; // Please can someone help me here.
                    try
                    {
                        connection.Open();
                        adapter = new SqlDataAdapter(sql, connection);
                        adapter.Fill(ds);
                        connection.Close();
                        ds.WriteXml("Subscription.xml");
                    }

                    catch (Exception ex)

                    {
                        MessageBox.Show(ex.Message.ToString());
                    }
 

4 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    There are so many ways  to fetch one row.It depends upon on your data.
     
    1.You can use "Top 1" command in select statement 
    2. You can use "Distinct" if there is duplication
    3. Set unique where clause condition 
    0
  • 0
    Hello Abdu, Possible to write for me sample of [Distinct] command {ActivationCode} will be the Column i will select from. sql= "" .// please , write for me query here. Thanks
    0
  • 0
    Hello Abdu, Possible to write for me sample of [Distinct] command {ActivationCode} will be the Column i will select from. sql= "" .// please , write for me query here. Thanks
    0
  • 0
    SELECT Distinct TOP 1 empname,empid from Table_Sub where ActivationCode = "" "
    0