C#.net中如何在TextBox中显示数据库查询结果如图,点击查选,在下面的textbox显示,代码如下。。。

C#.net中如何在TextBox中显示数据库查询结果如图,点击查选,在下面的textbox显示,代码如下。。。,第1张

你这个可以显示出来啊? if (thisDataSetTables["thistables"]RowsCount > 0) //如果有记录查到

{

TextBox1Text = thisDataSetTables["thistables"]Rows[0][0]ToString();

TextBox2Text = thisDataSetTables["thistables"]Rows[0][1]ToString();

TextBox3Text = thisDataSetTables["thistables"]Rows[0][2]ToString();

TextBox4Text = thisDataSetTables["thistables"]Rows[0][3]ToString();

TextBox5Text = thisDataSetTables["thistables"]Rows[0][4]ToString();

TextBox6Text = thisDataSetTables["thistables"]Rows[0][5]ToString();

}

这几条语句是显示的啊?

为什么你这里面要这么麻烦的写法了?

thiscommand = new SqlCommand("select from teacher where Terid='" + bhxm + "'", thisConnect);

}

//SqlDataAdapter myDataAdapter = new SqlDataAdapter();

thisAdapter = new SqlDataAdapter();

thisAdapterSelectCommand = thiscommand;//用到查询命令

thisDataSet = new DataSet();//产生数据

thisAdapterFill(thisDataSet, "thistables");

改成这样看这舒服点

SqlDataAdapter myDataAdapter = new SqlDataAdapter("select from teacher where Terid='" + bhxm + "'", thisConnect);

DataSet thisDataSet = new DataSet();//创建数据集对象

myDataAdapter Fill(thisDataSet );//填充数据集

if (thisDataSetTables[0]RowsCount > 0) //如果有记录查到

{

TextBox1Text = thisDataSetTables[0]Rows[0][0]ToString();

TextBox2Text = thisDataSetTables[0]Rows[0][1]ToString();

TextBox3Text = thisDataSetTables[0]Rows[0][2]ToString();

TextBox4Text = thisDataSetTables[0]Rows[0][3]ToString();

TextBox5Text = thisDataSetTables[0]Rows[0][4]ToString();

TextBox6Text = thisDataSetTables[0]Rows[0][5]ToString();

}

else

{

ResponseWrite("<script>alert('查找不到信息,请确认输入的信息是否正确!')</script>");

}

一 查阅

在Text1的KeyPress事件中加入代码,查阅时,在Text1里输入数据后,按Enter键作结束

Private Sub Text1_KeyPress(KeyAscii AsInteger)

If KeyAscii = 13 Then

Dim X As Integer

Dim CNN As New ADODBConnection

Dim rst As New ADODBRecordset

Dim SQ2 As String

CNNOpen "Provider=microsoftjetoledb40;data source="& AppPath & "\数据库名mdb"

SQ2 = "select from 表名"

rstOpen SQ2, CNN, adOpenKeyset, adLockOptimistic

if not rstEOF then

rstMovefirst

end if

For X = 1 To rstRecordCount

If Val(MeText1) = rst("A") Then ‘如果字段A是文本格式,Val()函数改为Trim()

MeText1 = rst("A")

MeText2 = rst("B")

Metext3 = rst("C")

Metext4 = rst("D")

Exit For

EndIf

rstMoveNext

Next X

rstClose

Set CCN = Nothing

End If

End Sub

二保存

Private Sub 保存_Click()

Dim X As Integer

Dim CNN As New ADODBConnection

Dim rst As New ADODBRecordset

Dim SQ2 As String

CNNOpen"Provider=microsoftjetoledb40;data source=" & AppPath &"\数据库名mdb"

SQ2 = "select from 表名"

rstOpen SQ2, CNN, adOpenKeyset,adLockOptimistic

rstAddNew

rst("A")= MeText1

rst("B")= MeText2 =

rst("C")=MeText3

rst("D")= MeText4

rstupdate

rstClose

Set CCN = Nothing

End Sub

三修改 删除

在DataGrid的RowColChange事件里加入

Private Sub DataGrid_RowColChange(LastRow As Variant, ByVal LastCol As Integer)

metext1=Datagridcolumns(0) '如果字段A是第一列,

end sub

点击修改或 删除 前,需在DataGrid表里点选需要修改或删除的记录,让该记录的第一列出现在textbox1里

Private Sub 修改_Click()

Dim X As Integer

Dim CNN As New ADODBConnection

Dim rst As New ADODBRecordset

Dim SQ2 As String

CNNOpen"Provider=microsoftjetoledb40;data source=" & AppPath &"\数据库名mdb"

SQ2 = "select from 表名"

rstOpen SQ2, CNN, adOpenKeyset,adLockOptimistic

if not rstEOF then

rstMovefirst

end if

For X = 1 To rstRecordCount

If Val(MeText1) = rst("A") Then '如果字段A是文本格式,Val()函数改为Trim()

rst("A")= MeText1

rst("B")= MeText2 =

rst("C")=MeText3

rst("D")= MeText4

rstupdate

ExitFor

EndIf

rstMoveNext

Next X

rstClose

Set CCN = Nothing

End Sub

Private Sub 删除_Click()

Dim X As Integer

Dim CNN As New ADODBConnection

Dim rst As New ADODBRecordset

Dim SQ2 As String

CNNOpen"Provider=microsoftjetoledb40;data source=" & AppPath &"\数据库名mdb"

SQ2 = "select from 表名"

rstOpen SQ2, CNN, adOpenKeyset,adLockOptimistic

if not rstEOF then

rstMovefirst

end if

For X = 1 To rstRecordCount

If Val(MeText1) = rst("A") Then '如果字段A是文本格式,Val()函数改为Trim()

rstdelete

Exit For

EndIf

rstMoveNext

Next X

rstClose

Set CCN = Nothing

End Sub

string i = "select sum(toolNumber) from mtctoolstable where tooltime between year1+month1 and year2+month2 and toolsign=0 and toolName=toolName";

第二个toolName应该是个参数吧,应该

string i = "select sum(toolNumber) from mtctoolstable where tooltime between year1+month1 and year2+month2 and toolsign=0 and toolName='"+toolName+"'";

然后你的year1+month1 你看下结果是什么,是日期的格式吗?应该不是吧。

格式相同才能比较撒。 如果2008-1-1和20081 怎么比较。

以上就是关于C#.net中如何在TextBox中显示数据库查询结果如图,点击查选,在下面的textbox显示,代码如下。。。全部的内容,包括:C#.net中如何在TextBox中显示数据库查询结果如图,点击查选,在下面的textbox显示,代码如下。。。、VB数据库如何用text文本框插入数据和读取显示数据、C#.net中如何在TextBox中显示数据库查询结果等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9483806.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-28
下一篇 2023-04-28

发表评论

登录后才能评论

评论列表(0条)

保存