Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
2.00/5 (4 votes)
See more: , +
C#
protected void btn_View_Click(object sender, EventArgs e)
   {
       TextBox tb = (TextBox)Master.FindControl("txtEmployee_code");

       comm.Connection = con;

       con.Open();
       {
           SqlCommand cmd = new SqlCommand("select osi_int_from_bank='" + txtOSIInterstFromBank.Text + "' from other_source_income  WHERE em_id=" + tb.Text + "", con);

           cmd.ExecuteNonQuery();
           con.Close();
       }


   }
Posted
Updated 31-May-12 19:46pm
v2
Comments
[no name] 1-Jun-12 1:43am    
if error come, please post it..
Rajesh Kariyavula 1-Jun-12 1:57am    
What is the issue?
Prosan 1-Jun-12 3:44am    
what error is coming show us

C#
protected void btn_View_Click(object sender, EventArgs e)
{
}


There. I've removed your sql injection attack vector. :)
 
Share this answer
 
Comments
Sandeep Mewara 1-Jun-12 2:58am    
5!
in your sqlcommand you write select something=anotherthing that is incorrect this is the reason of syntax error near the key work from!
you select one,or a group, or set alias to them but select x=y is totally wrong!
 
Share this answer
 
are you sure you are wanting to select i think you want to update data. if yes than write update query in place of select query.
like that

C#
SqlCommand cmd = new SqlCommand("update other_source_income  set osi_int_from_bank='" + txtOSIInterstFromBank.Text + "' WHERE em_id=" + tb.Text + "", con);


if not than write like this
SQL
SqlCommand cmd = new SqlCommand("select osi_int_from_bank from other_source_income  WHERE em_id=" + tb.Text + "", con);


and in select command don't use cmd.ExecuteNonQuery()
 
Share this answer
 
v2
Use SqlDataReader ....


<pre lang="cs">rdr = cmd.ExecuteReader();

SqlDataReader rdr = null;
lbFound.Items.Clear();
while(rdr.Read())
{
//your code here

}</pre>
 
Share this answer
 
also try this :

C#
protected void btn_View_Click(object sender, EventArgs e)
{
TextBox tb = (TextBox)Master.FindControl("txtEmployee_code");
 
comm.Connection = con;
 
con.Open();
{
SqlDataAdapater ad = new SqlDataAdapter("select osi_int_from_bank=" + txtOSIInterstFromBank.Text + " from other_source_income WHERE em_id='" + tb.Text + "'", con);
Dataset ds=new Dataset();
ad.fill(ds); 

if(ds.Tables[0].rows.count!=0)
{
         //Do Something 
}
else
{
          // No Record Found
}


con.Close();
}
 

}


Hope this help You..
 
Share this answer
 
v3
Comments
2011999 1-Jun-12 1:52am    
Incorrect syntax near the keyword 'from'.
[no name] 1-Jun-12 1:58am    
please use above code and try...
John Orendt 1-Jun-12 2:31am    
solution 1 sql is a SELECT, aka Query, why are you using cmd.ExecuteNonQuery();
2011999 1-Jun-12 2:32am    
same error display Incorrect syntax near the keyword 'from'.
[no name] 1-Jun-12 4:29am    
sorry MyMistake.... you use SqldataAdapter for Fetching the Data. i update the code.

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