TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
SAM J
NA
24
33.2k
ERROR - Must Declare Scalar Variable - C#.net/SQL server 2005
Mar 10 2011 9:28 AM
I am writing the below code in C#.net for a windows application, and using SQL Server 2005.
private void button2_Click(object sender, EventArgs e)
{
try
{
int i = Convert.ToInt32(textBox2.Text);
string str = textBox1.Text;
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = "Data Source=DUGDOO;Initial Catalog=master;User ID=sa;Password=sa";
SqlCommand scd = new SqlCommand("INSERT INTO T1(name1, id) VALUES (@textBox1, @textBox2)", cnn);
scd.Parameters.AddWithValue("@name1", SqlDbType.VarChar).Value = textBox1.Text;
scd.Parameters.AddWithValue("@id", SqlDbType.Int).Value = Convert.ToInt32(textBox2.Text);
cnn.Open();
scd.ExecuteNonQuery();
MessageBox.Show("Inserted");
cnn.Close();
}
catch (Exception e1)
{ MessageBox.Show(""+e1); }
}
I execute the application, enter name(varchar), id(int) in the txtboxs i get error - "Must declare Scalar Variable at @textBox1" - Pls Help. I cudnt find any solution.
Reply
Answers (
2
)
C# equivelent of a VBscript sub routine
storing the image in database