Click here to Skip to main content
15,914,444 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Please help.

I am getting an error on strconnectionstring.

This code is to execute action queries sqlcommand:

SqlConnection cnn = new SqlConnection();
            cnn.ConnectionString = strconnectionstring;
            cnn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = cnn;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "update measurementunit measurement=@measurment, mucode =@mucode";
            SqlParameter p1 = new SqlParameter("@measurment", txtmu.Text);
            SqlParameter p2 = new SqlParameter("@mucode", txtmucode.Text);
            cnn.Close();
Posted
Updated 29-Sep-10 0:43am
v5
Comments
Hiren solanki 28-Sep-10 6:58am    
what is your effort so far, if so then put code snippets so that we can have clear understanding.
aayu 28-Sep-10 7:02am    
hmmmm i said i have put the code in my previous question
Hiren solanki 28-Sep-10 7:19am    
so here there is facility to attach previous post using link.
Om Prakash Pant 28-Sep-10 7:23am    
Another guide for beginners:
http://www.codeproject.com/KB/database/sql_in_csharp.aspx
Dalek Dave 29-Sep-10 3:43am    
Edited for Grammar and CodeBlock.

If it is very urgent then you can use LINQ to SQL.
Please check the following link:
http://www.codeproject.com/KB/linq/LINQSQLCS.aspx[^]
 
Share this answer
 
v2
Comments
Hiren solanki 28-Sep-10 9:38am    
proper linking.
Please check the following link:

http://dotnetperls.com/datatable[^]

Please check the following tutorial:
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson03.aspx[^]
 
Share this answer
 
v2
Comments
aayu 28-Sep-10 7:03am    
no this wont work
Another guide for beginners:
http://www.codeproject.com/KB/database/sql_in_csharp.aspx
 
Share this answer
 
Comments
Hiren solanki 28-Sep-10 9:37am    
answer only once.
Om Prakash Pant 29-Sep-10 1:17am    
Well, the question is generic and there can be more than one answer..
On Page load event write this code


private void page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Server=NGENIOUS-WSSDEV\SQLEXPRESS;Database=MIC;Trusted_Connection= True");
// SqlCommand cmd = new SqlCommand("select * from measurementunit",conn);
SqlDataAdapter da = new SqlDataAdapter("select * from measurementunit",conn);
conn.Open();
DataSet ds = new DataSet();

da.Fill(ds, "measurementunit");
conn.Close();
}


then on click of button




private void btninsert_Click(object sender, EventArgs e)
{
SqlConnection cnn = new SqlConnection(@"Server=NGENIOUS-WSSDEV\SQLEXPRESS;Database=MIC;Trusted_Connection= True");

// cnn.ConnectionString = ;
cnn.Open();

// cmd.Connection = cnn;
//cmd.CommandType = CommandType.Text;

SqlParameter p1 = new SqlParameter("@measurment", txtmu.Text);
SqlParameter p2 = new SqlParameter("@mucode", txtmucode.Text);
string query = "insert into measurementunit values('" + p1.Value + "','" + p2.Value + "')";
SqlCommand cmd = new SqlCommand(query,cnn);
// cmd.CommandText = "insert into measurementunit('"+ p1.Value+"','"+p2.Value+"')";
//cmd.CommandType = CommandType.Text;
//SqlDataReader dr = cmd.ExecuteReader();

cmd.ExecuteNonQuery();
cnn.Close();


MessageBox.Show("Your information have Submited");
}



First code will help you to do connection of code and button click will help you to insert data in sql server db :laugh: :thumbsup::rose:
 
Share this answer
 

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



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