public void add(Student std)
{
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into dab (name) values (@name)", con);
cmd.Parameters.AddWithValue("@name", name); cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
}
public void add(Student std)
{
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into dab (name) values (@name)", con);
cmd.Parameters.AddWithValue("@name", name); cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
}
am getting
the error is
The parameterized query '(@name nvarchar(4000))insert into dab (name) values (@name)' expects the parameter '@name', which was not supplied.
i posted this on many forum but no one resolve it plz help me out
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Practice1
{
public class Student
{
public int id { get; set; }
public string name { get; set; }
public void add(Student std)
{
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into dab (name) values (@name)", con);
cmd.Parameters.AddWithValue("@name", SqlDbType.VarChar).Value = name;
cmd.ExecuteNonQuery();
}
}
}
}
And My connection string in web.config file
<connectionstrings>
<add name="DBCS">
connectionString ="Data Source=BHUSHAN-PC\SQLEXPRESS; Initial Catalog=Practice; Integrated Security=SSPI"
providerName="System.Data.SqlClient"/>
</add>
</connectionstrings>
Friends in Student.cs file
name is textbox id name....
<table>
<tbody>
<tr>
<td class="style2">
First Name
</td>
</tr>
</tbody>
</table>
<td class="style6">
<asp:TextBox ID="name" runat="server" OnTextChanged="TextBox1_TextChanged">
</td>
<table>
<tbody>
<tr>
<td>
the error is
The parameterized query '(@name nvarchar(4000))insert into dab (name) values (@name)' expects the parameter '@name', which was not supplied.