i have this code...i m retreiveing did from selected name........
i want to assign this to varible because i want to use this variable to another place...
i hope i will get help here..

MyDataAdapter = new SqlDataAdapter("select D_Id from tblDepart where D_Name = '" + D_Name + "'", Myconnection);
      
         myDataSet = new DataSet();
         MyDataAdapter.Fill(myDataSet);
       int a = Convert.ToInt16(myDataSet);

Recommended Answers

All 4 Replies

Fill() method create an instance of DataTable and DataTable instance hold references of rows (fetched result).

int a=0;
 if(myDataSet.Tables[0].Rows.Count!=0)
  {
    a= (int) myDataSet.Tables[0].Rows[0][0]; //1st row and 1st column
  }

thanks man its working.........:)
thanks again..

Just to add:
... be careful here. adatapost is correct, but be careful in two things
- row index
- column index

You have to state the correct indexes, and for the column you can even state the column name!

i want to assign a variable which contains set of values in a row orderby rollno.
that variable would be send to mobile number as a text. how to write the code. can i use here for datatable or datareader.quickly. send ur replies to my mail id also. Here is my mail id vpsingh136@gmail.com

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.