The parameterized query @Fname expects a parameter which was not supplied.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="font-family:Times New Roman,serif If anyone has been keeping a score, I posted several questions here today and yesterday.<span>
So many of my questions were answered.<span> Thanks for that!!<span>
I have one more now (hopefully not too many more).<span> Here is my code:
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
<span style="color:blue private <span style="color:blue void button6_Click(<span style="color:blue object sender,
<span style="color:#2B91AF EventArgs e)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
{
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
<span style="color:#2B91AF SqlConnection con = <span style="color:blue
new System.Data.SqlClient.<span style="color:#2B91AF SqlConnection();
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
con = <span style="color:blue new System.Data.SqlClient.<span style="color:#2B91AF SqlConnection();
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
con.ConnectionString = <span style="color:#A31515 "Server=excel-pc;Database=Northwind.MDF;Trusted_Connection=True;";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
con.Open();
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
<span style="color:#2B91AF SqlDataAdapter da = <span style="color:blue
new <span style="color:#2B91AF SqlDataAdapter();
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
<span style="color:blue for (<span style="color:blue int i = 0; i <= dataGridView1.Rows.Count - 1; i++)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
{
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
<span style="color:#2B91AF String insertData = <span style="color:#A31515
"INSERT INTO Import_List(Fname, Lname, Age) VALUES (@Fname, @Lname, @Age)";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
<span style="color:#2B91AF SqlCommand cmd = <span style="color:blue
new <span style="color:#2B91AF SqlCommand(insertData, con);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
cmd.Parameters.AddWithValue(<span style="color:#A31515 "@Fname", dataGridView1.Rows.Cells[0].Value);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
cmd.Parameters.AddWithValue(<span style="color:#A31515 "@Lname", dataGridView1.Rows.Cells[1].Value);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
cmd.Parameters.AddWithValue(<span style="color:#A31515 "@Age", dataGridView1.Rows.Cells[2].Value);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
da.InsertCommand = cmd;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
cmd.ExecuteNonQuery();
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
}
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
con.Close();
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-family:Times New Roman,serif <span>
}
<span style="font-family:Times New Roman,serif
<span style="font-family:Times New Roman,serif Here is the error message:
<span style="font-family:Times New Roman,serif <img alt="" src="http://social.msdn.microsoft.com/Forums/getfile/188174
<span style="font-family:Times New Roman,serif What am I doing wrong here???
<span style="font-family:Times New Roman,serif
<
Ryan Shuell
<br/>

View the full article
 
Back
Top