0

データベースからテキストにデータを取得しようとしています! 貼り付けたコードは正常に動作し、例外は発生しませんが、問題は、取得したデータベースから必要なデータを取得できないことですSystem.Data.SqlClient.SqlDataReader

問題を整理するのを手伝ってください...

////コード////

private void ReplaceBookmarkText(Microsoft.Office.Interop.Word.Document doc, string bookmarkName,string text)
{
   object objI=1 ;
   object count = 7;
   object oCount = Microsoft.Office.Interop.Word.WdConstants.wdForward;
   object oUnit = Microsoft.Office.Interop.Word.WdUnits.wdCharacter;
   int number;
   //here is your name, store it where ever you want:
   bookmarkName = doc.Bookmarks.get_Item(ref objI).Name;
   //bookmarkEnd = doc.Bookmarks.get_Item(ref objI).End;
   //bookmarkStart = doc.Bookmarks.get_Item(ref objI).Start;
   number = doc.Bookmarks.get_Item(ref objI).Range.MoveEnd(ref oUnit, ref count);
   //bookmarkEnd = doc.Bookmarks.get_Item(ref objI).Start;
   string bookmarkValue = doc.Bookmarks.get_Item(ref objI).Range.Text;
   MessageBox.Show(bookmarkValue);
   string db_name = "";

   try
   {
      sql_con = new SqlConnection(con_str);
      sql_con.Open();

      //"SELECT FirstName FROM ContactPerson WHERE (Contact_ID = " + fNameTemp + ")");
      // select s_name from student where s_reg = '11-ARID-4204'
      // string sql_query = ("select s_name from student where (s_reg = " + txtboxrollno + ")");
      //"Select * from logintable where password=" + "'TextBox1.Text'";
      sql_cmd = sql_con.CreateCommand();
      string qrery = ("select s_name from student where (s_reg = " + "'txtboxrollno.text'" + ")");
      SqlCommand cmd = new SqlCommand(qrery,sql_con);
      //sql_cmd.CommandText = ("select s_name from student where (s_reg = " + txtboxrollno.Text.Trim() + ")");
      cmd.ExecuteNonQuery();
      MessageBox.Show(cmd.ToString());
      SqlDataReader sdr; 
      sdr = cmd.ExecuteReader();
      //textBox1.Text = sdr.ToString();
      db_name = textBox1.Text;

      while(sdr.Read())
      {
         //textBox1.Text = sdr["s_name"].ToString();
         textBox1.Text = cmd.ExecuteScalar().ToString();
         //txtpatientid.Text = command.ExecuteScalar().ToString();
         //fNameTextBox.Text = sdr["FirstName"].ToString();
      }
   }
}
4

1 に答える 1