本文介绍了从数据库获取名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何显示此查询的输出到文本框

Me.KasriTableAdapter.Adapter.SelectCommand.CommandText =从kasri中选择名称

其中id = 1"


我需要一个名称,其id = 1

并将其发送到文本框!!

how can i show this query''s output to a textbox

Me.KasriTableAdapter.Adapter.SelectCommand.CommandText = "SELECT name FROM kasri

where id=1"


i need a name that its id = 1

and send it to a text box !!

推荐答案

Con = new SqlConnection("Your Connection string ");
            Con.Open();
            Cmd = new SqlCommand("SELECT Name from kasri WHERE Id = @ID", Con);
            Cmd.Parameters.AddWithValue("@ID", ID);
            dr = Cmd.ExecuteReader();

            if (dr.Read())
            {
               strCountryName = dr["Name"].ToString();
            }


Con = new SqlConnection("Your Connection string ");
Con.Open();
Cmd = new SqlCommand("SELECT Name from kasri WHERE Id = @ID", Con);
Cmd.Parameters.AddWithValue("@ID", ID);
string strName = Cmd.ExecuteScalar();
strCountryName = strName.toString();


这篇关于从数据库获取名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 12:30