Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am new to C# and am stuck on this error. All i want to do is get info from the user and save it to a database. Any help is much appreciated. Thanks in advanced.



VB
Error   1   'string' does not contain a definition for 'Parameters' and no extension method 'Parameters' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)


Here is the code

string pat = textBox1.Text.Trim();
            string res = textBox2.Text.Trim();
            
            if (@pat.Length == 0 || @res.Length == 0)
            {
                MessageBox.Show("Please enter something in the boxes.");
                return;
            }
            MessageBox.Show(@pat +" " + @res);
           
            SqlConnection cnn = new SqlConnection(OMSDB_Connection_String);
            string command = "Insert INTO OTM_unsubscriptions (dbPatCnt, dbRespCnt, Email, PracticeID) " +
                                 " VALUES (@pat,@res, 1, 1)";
            SqlCommand cmd = new SqlCommand(command, cnn);
            command.Parameters.Add(new SqlParameter(@pat, "valueOf_dbPatCnt"));
            command.Parameters.Add(new SqlParameter(@res, "valueOf_dbRespCnt"));
            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();
Posted
Comments
Derek1214 4-May-11 0:03am    
Thanks for the help.

1 solution

First of all, why are you putting @ on your string variables? @ is only used on SQL and not C# variables. You might want to change your code to this.

string pat = textBox1.Text.Trim();
            string res = textBox2.Text.Trim();
            
            if (pat.Length == 0 || res.Length == 0)
            {
                MessageBox.Show("Please enter something in the boxes.");
                return;
            }
            MessageBox.Show(pat +" " + res);
           
            SqlConnection cnn = new SqlConnection(OMSDB_Connection_String);
            string command = "Insert INTO OTM_unsubscriptions (dbPatCnt, dbRespCnt, Email, PracticeID) " +
                                 " VALUES (@valueOf_dbPatCnt,@valueOf_dbRespCnt, 1, 1)";
            SqlCommand cmd = new SqlCommand(command, cnn);
            command.Parameters.Add(new SqlParameter("@valueOf_dbPatCnt", pat));
            command.Parameters.Add(new SqlParameter("@valueOf_dbRespCnt", res));
            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();


I simply removed the @ on the variables and fixed the code where you added your parameters. It seems your still a little confused with ADO.Net. I suggest you read more.
 
Share this answer
 
Comments
Derek1214 4-May-11 0:03am    
Thanks
walterhevedeich 4-May-11 0:26am    
You might want to mark this question as solved if this solves your question. It would serve as a reference for others who encounter similar problem.
Hemant__Sharma 4-May-11 0:15am    
@Derek1214 - if the answer has helped you always mark it as answer and vote for it. It helps other to understand similar issues and their solutions.

thanks
Kim Togo 4-May-11 3:30am    
My 5. Nice catch.
walterhevedeich 4-May-11 3:43am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900