高手进来救命了,在线等 radiobuttonlist 读取数据库

yanpangzishiwo 2009-09-23 03:41:22
已建好的数据库,用radiobuttonlist来读取里面的数据,显示出来
Sub list_room()
Dim strSQL As String
strSQL = "SELECT [p_id], [p_name] FROM [product_sp] order by p_id desc"

rd_num.DataSource = product_sp '数据库表名错误
rd_num.DataBind()
rd_num.DataTextField = "p_name"
rd_num.DataValueField = "p_id"
...全文
105 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
Iovswety 2009-09-23
  • 打赏
  • 举报
回复
78062463
yanpangzishiwo 2009-09-23
  • 打赏
  • 举报
回复
你的qq号是多少了,想向你请教一些问题
yanpangzishiwo 2009-09-23
  • 打赏
  • 举报
回复
但加上报错语句不能加到方法体内
Iovswety 2009-09-23
  • 打赏
  • 举报
回复

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
dim strsql as string = "SELECT [p_id], [p_name] FROM [product_sp] order by p_id desc"
rd_num.DataSource = getDt(strSql)
rd_num.DataTextField = "p_name"
rd_num.DataValueField = "p_id"
rd_num.DataBind()
end sub

不是放在getdt里面的。。
还有,Dim conString As String = "Data Source=localhost;Initial Catalog=aaa;Integrated Security=True"
这个事我自己随手打的,你要根据你自己连接数据库的实际情况改的。。。
yanpangzishiwo 2009-09-23
  • 打赏
  • 举报
回复
#Region "调用物料种类链表"
Sub list_data()
getDt(ByVal strSql As String) As System.Data.DataTable
Dim con As New System.Data.SqlClient.SqlConnection
Dim conString As String = "Data Source=localhost;Initial Catalog=aaa;Integrated Security=True"
con.ConnectionString = conString
Dim sda As New System.Data.SqlClient.SqlDataAdapter(strSql, con)
Dim dats As New System.Data.DataSet
Try
sda.Fill(dats)
Catch ex As Exception

End Try
Return dats.Tables(0)
rd_num.DataSource = getDt(strSql)
rd_num.DataTextField = "p_name"
rd_num.DataValueField = "p_id"
rd_num.DataBind()
End Function

#End Region

想在前面加 sub list_data()
yanpangzishiwo 2009-09-23
  • 打赏
  • 举报
回复
#Region "调用物料种类链表"
Public Function getDt(ByVal strSql As String) As System.Data.DataTable
Dim con As New System.Data.SqlClient.SqlConnection
Dim conString As String = "Data Source=localhost;Initial Catalog=aaa;Integrated Security=True"
con.ConnectionString = conString
Dim sda As New System.Data.SqlClient.SqlDataAdapter(strSql, con)
Dim dats As New System.Data.DataSet
Try
sda.Fill(dats)
Catch ex As Exception

End Try
Return dats.Tables(0)
rd_num.DataSource = getDt(strSql)
rd_num.DataTextField = "p_name"
rd_num.DataValueField = "p_id"
rd_num.DataBind()
End Function

#End Region


我用的是方法呀,怎么加到方法内呢?
Iovswety 2009-09-23
  • 打赏
  • 举报
回复
没有错。。。constring就是连接数据库的语句嘛
Private conString As String = "Data Source=localhost;Initial Catalog=aaa;Integrated Security=True"
yanpangzishiwo 2009-09-23
  • 打赏
  • 举报
回复
10楼,con.ConnectionString = conString
这句不对吧,是不写错了
Iovswety 2009-09-23
  • 打赏
  • 举报
回复
rd_num.DataSource = product_sp 这样肯定绑定不了啦
那个只是个数据库表名来的

Public Function getDt(ByVal strSql As String) As System.Data.DataTable
Dim con As New System.Data.SqlClient.SqlConnection
con.ConnectionString = conString
Dim sda As New System.Data.SqlClient.SqlDataAdapter(strSql, con)
Dim dats As New System.Data.DataSet
Try
sda.Fill(dats)
Catch ex As Exception

End Try
Return dats.Tables(0)
End Function


rd_num.DataSource =GetDt(strsql)
rd_num.DataTextField = "p_name"
rd_num.DataValueField = "p_id"
rd_num.DataBind()
yanpangzishiwo 2009-09-23
  • 打赏
  • 举报
回复
不对,希望vb语言回答,分有加倍
liujunhappy2005 2009-09-23
  • 打赏
  • 举报
回复
Dim strSQL As String
strSQL = "SELECT [p_id], [p_name] FROM [product_sp] order by p_id desc"
DataTable DT = new DataTable();

Dim Conn = new SqlConnection(connString);//connString数据库链接字符串
Dim SQLCommand = new SqlDataAdapter(strSQL, Conn);
try
{
SQLCommand.Fill(DT);
}
catch (Exception Ex)
{
throw Ex;
}
rd_num.DataSource = DT '数据库表名错误
rd_num.DataBind()
rd_num.DataTextField = "p_name"
rd_num.DataValueField = "p_id"
nihaimeiyoudenglu 2009-09-23
  • 打赏
  • 举报
回复
大哥,DataSource 这个里面放的是datatable or datasource.你只放个表名怎么行呢.
yanpangzishiwo 2009-09-23
  • 打赏
  • 举报
回复
那我应该怎么做?
yanpangzishiwo 2009-09-23
  • 打赏
  • 举报
回复
rd_num.DataTextField = "p_name"
rd_num.DataValueField = "p_id"
放到
rd_num.DataBind()前面
报错:DataBinder.Eval:“System.Char”不包含名称为 p_name 的属性。
liujunhappy2005 2009-09-23
  • 打赏
  • 举报
回复
DataSource 应该是数据源对象,而不是表名,你的数据都还没从数据库中取出来,怎么付给DataSource ?
yanpangzishiwo 2009-09-23
  • 打赏
  • 举报
回复
product_sp 是表名
liujunhappy2005 2009-09-23
  • 打赏
  • 举报
回复
DataSource 应该是datatable 对象,product_sp是什么?
还有把
rd_num.DataTextField = "p_name"
rd_num.DataValueField = "p_id"
放到
rd_num.DataBind()
前面试试
yanpangzishiwo 2009-09-23
  • 打赏
  • 举报
回复
兄弟姊妹么,高手么,没人会吗?
自己顶吧!

16,720

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧