为什么ASP.net中用得好好的ado.net连接在vb.net中不行

lsgl 2003-01-07 10:13:00
我在asp.net用得好好的连接,可是到了vb.net中,就不能用了,这是怎么回事呢?有没有哪位能给我一个连接示例,如果可以最好能加上添加、删除等。谢谢!!!
...全文
35 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lsgl 2003-01-07
  • 打赏
  • 举报
回复
我要的是手工写的啊!你不会在ASP.net或vb.net中用控件吧!!!我昏!我不要控件啊!我要手 写的adodb的代码!I 狂昏!!!!!
qieyj 2003-01-07
  • 打赏
  • 举报
回复

'删除
Sub DataGrid1_DeleteCommand(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
Dim deleteCmd As String
Dim deCommand As SqlCommand

deleteCmd = "DELETE FROM liuyan WHERE id=" & Int32.Parse(DataGrid1.Items(Int32.Parse(e.Item.ItemIndex.ToString())).Cells(0).Text)
deCommand = New SqlCommand(deleteCmd, SqlConnection1)
Try
deCommand.Connection.Open()
deCommand.ExecuteNonQuery()
Catch ex As SqlException
lblError.Text = "ERROR: Could not delete record from Orders Details table"
deCommand.Connection.Close()
Exit Sub
End Try
deCommand.Connection.Close()
End Sub
qieyj 2003-01-07
  • 打赏
  • 举报
回复
'SqlDataAdapter1
'
Me.SqlDataAdapter1.InsertCommand = Me.SqlInsertCommand1
Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
Me.SqlDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "liuyan", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("id", "id"), New System.Data.Common.DataColumnMapping("subject", "subject"), New System.Data.Common.DataColumnMapping("detail", "detail"), New System.Data.Common.DataColumnMapping("username", "username"), New System.Data.Common.DataColumnMapping("createdtime", "createdtime")})})
'
'SqlInsertCommand1
'
Me.SqlInsertCommand1.CommandText = "INSERT INTO liuyan(subject, detail, username, createdtime) VALUES (@subject, @det" & _
"ail, @username, @createdtime); SELECT id, subject, detail, username, createdtime" & _
" FROM liuyan"
Me.SqlInsertCommand1.Connection = Me.SqlConnection1
Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@subject", System.Data.SqlDbType.VarChar, 50, "subject"))
Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@detail", System.Data.SqlDbType.VarChar, 5000, "detail"))
Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@username", System.Data.SqlDbType.VarChar, 50, "username"))
Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@createdtime", System.Data.SqlDbType.DateTime, 8, "createdtime"))
'
'SqlConnection1
'
Me.SqlConnection1.ConnectionString = "data source=QIEYJ;initial catalog=liuyan;persist security info=False;user id=sa;w" & _
"orkstation id=QIEYJ;packet size=4096"
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "SELECT id, subject, detail, username, createdtime FROM liuyan"
Me.SqlSelectCommand1.Connection = Me.SqlConnection1
lsgl 2003-01-07
  • 打赏
  • 举报
回复
我知道。还有吗?
Wolfyee 2003-01-07
  • 打赏
  • 举报
回复
Dim myConnection As New SqlConnection("server=" + Application("Server") + ";uid=gg;pwd=hgg;database=aa")
连接就是这一句,使用:
myConnection.Open()打开连接

16,722

社区成员

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

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