![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi EveryBody: Whey when I use the following code trying to inser my data to database it did not work: Dim mydatasource As New SqlDataSource mydatasource.ConnectionString = ConfigurationManager.ConnectionStrings("LocalSqlSe rver").ToString mydatasource.InsertCommandType = SqlDataSourceCommandType.Text mydatasource.InsertCommand = "INSERT INTO husam_Tab(user_Name,user_Password,user_Email,user_ Squestion,user_Sanswer) Values(@user_Name,@user_Password,@user_Email,@user _Squestion,@user_Sanswer)" mydatasource.InsertParameters.Add("user_Name", TextBox1.Text) mydatasource.InsertParameters.Add("user_Password", TextBox2.Text) mydatasource.InsertParameters.Add("user_Email", TextBox4.Text) mydatasource.InsertParameters.Add("user_Squestion" , TextBox5.Text) mydatasource.InsertParameters.Add("user_Sanswer", TextBox6.Text) While Whe I use the foolowing code to insert the same data to my database Its Work: Dim cmd As SqlCommand Dim scon As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrin gs("LocalSqlServer").ConnectionString) Dim sql As String scon.Open() sql = "INSERT INTO husam_Tab(user_Name,user_Password,user_Email,user_ Squestion,user_Sanswer)" + "Values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "')" cmd = New SqlCommand(sql, scon) cmd.ExecuteNonQuery() scon.Close() Note: I ma using SQL server 2005 Not Express edition so my database file it is not attached to my solution. Any help will be completlly appreciated regard's Husam |
#3
| |||
| |||
|
|
Add "@" to the parameter name: mydatasource.InsertParameters.Add("@user_Name", TextBox1.Text) mydatasource.InsertParameters.Add("@user_Password" , TextBox2.Text) ... |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |