C# ASP.Net-VB到.MDF的连接
我正在尝试在.net应用程序中使用VB更新我的数据库。我已经在我的应用程序代码文件夹中添加了一个数据集文件,并将我的数据库上载到其中。我似乎无法更新表并向其插入新行。(我不熟悉数据库)数据库文件是.mdf,我遵循了数据访问层(生成的sql语句)的说明 这是我的web.config文件:C# ASP.Net-VB到.MDF的连接,c#,mysql,sql,asp.net,vb.net,C#,Mysql,Sql,Asp.net,Vb.net,我正在尝试在.net应用程序中使用VB更新我的数据库。我已经在我的应用程序代码文件夹中添加了一个数据集文件,并将我的数据库上载到其中。我似乎无法更新表并向其插入新行。(我不熟悉数据库)数据库文件是.mdf,我遵循了数据访问层(生成的sql语句)的说明 这是我的web.config文件: <configuration> <connectionStrings> <add name="ConnectionString" connectionString="Da
<configuration>
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\CreatePatient.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
<add name="CreatePatientConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\CreatePatient.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0"/>
</system.web>
</configuration>
其想法是填写帐户凭据并将其存储在数据库中。如果我遗漏了任何信息,请告诉我。我是stackoverflow、ASP.net和SQL的新手,需要帮助您的代码缺少将数据插入数据库的调用
If IsValid Then
Try
Dim strSQL = "insert into CreatePatient (Account, Password, FirstName, LastName, " & _
"Address, HomePhone, Mobile, City, State, Zip, Social, Age, Gender, " & _
"Height, Weight, Marital, Spouse) values (@Account, @Password, @FirstName, " & _
"@LastName, @Address, @HomePhone, @Mobile, @City, @State, @Zip, @Social, " & _
"@Age, @Gender, @Height, @Weight, @Marital, @Spouse)"
Using CCSQL = new SqlConnection(ConfigurationManager.ConnectionStrings("CreatePatientConnectionString").ConnectionString)
Using CCUser = new SqlCommand(strSQL, CCSQL)
CCSQL.Open()
CCUser.Parameters.Add("@Account", Data.SqlDbType.VarChar).Value = Account.Text
......
CCUser.ExecuteNonQuery()
End Using
End Using
Response.Redirect("ProcedureSelectionForm.aspx")
Catch ex As Exception
ErrorTXT.Text = ex.Message
End Try
End If
我还附上了在a中创建
SqlConnection
和SqlCommand
,以确保正确关闭和处理连接,并在出现异常时创建该命令感谢您的帮助。你很高兴能帮上忙,作为这个网站的新用户,我建议你读一下这篇文章
If IsValid Then
Try
Dim strSQL = "insert into CreatePatient (Account, Password, FirstName, LastName, " & _
"Address, HomePhone, Mobile, City, State, Zip, Social, Age, Gender, " & _
"Height, Weight, Marital, Spouse) values (@Account, @Password, @FirstName, " & _
"@LastName, @Address, @HomePhone, @Mobile, @City, @State, @Zip, @Social, " & _
"@Age, @Gender, @Height, @Weight, @Marital, @Spouse)"
Using CCSQL = new SqlConnection(ConfigurationManager.ConnectionStrings("CreatePatientConnectionString").ConnectionString)
Using CCUser = new SqlCommand(strSQL, CCSQL)
CCSQL.Open()
CCUser.Parameters.Add("@Account", Data.SqlDbType.VarChar).Value = Account.Text
......
CCUser.ExecuteNonQuery()
End Using
End Using
Response.Redirect("ProcedureSelectionForm.aspx")
Catch ex As Exception
ErrorTXT.Text = ex.Message
End Try
End If