因毕业设计问各位高手们连接SQL的问题,小弟新手,谢谢了!
我想问一下,我不想在Default.aspx用
<%@ Import Namespace= "System.Data " %>
<%@ Import Namespace= "System.Data.Sqlclient " %>
这种方法连入SQL,我想用在Default.aspx.vb里面用VB.NET的语言写,请问应该怎样写啊?谢谢了!
------解决方案--------------------可以啊.
改成vb的就可以了.
SqlConnection conn =null;
SqlDataAdapter dapt = null;
DataSet ds = new DataSet();
string strConnectionString = "Data Source=.;initial catalog=数据库;uid=sa;pwd=xxx ";
string strSQL = "SELECT 字段 from 表 "
try
{
conn = new SqlConnection(strConnectionString);
conn.Open();
dapt = new SqlDataAdapter(strSQL,conn);
dapt.Fill(ds, "table1 ");
DataTable dt = ds.Tabls[0];
if(dt.Rows.Count > 0)
{
this.Text1.Text = dt.Rows[0][ "字段 "].ToString();
}
}
catch(
System.Exception e)
{
this.Text1.Text = "错误 "+e.Message;
}
finally
{
if(conn!=null)
conn.Dispose();
if(dapt!=null)
dapt.Dispose();
}
------解决方案--------------------Dim student_id As String = Request.Cookies( "userInf ").Values( "userID ")
Dim mySqlConnection As String
mySqlConnection = "Data Source=localhost;initial catalog=user;user id=lgw;password=lgw;connect timeout=30 "
Dim connuser As New Data.SqlClient.SqlConnection(mySqlConnection)
conn.Open()
Dim strSql As String = "select * from users where id= " & student_id