Sqlexception was occured? [Resolved]

Posted by Sudheep.grandhe under C# on 11/14/2011 | Points: 10 | Views : 1034 | Status : [Member] | Replies : 2
Hi,

when i was found the error in my gridview coding.can you rectify this error.please do the needful.

Error:
Invalid column name 'quanity'.

SqlConnection con1 = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd1 = new SqlCommand("select particulars,orderno,quanity,perprice,amount from tbl_report1 where invoiceid=@id1", con1);
cmd1.Parameters.AddWithValue("@id1", id1);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataTable dt1 = new DataTable();
da1.Fill(dt1);//error shows here
if (dt1.Rows.Count > 0)
{
GridView2.DataSource = dt1;
con.Close();
}
else
{
GridView2.DataSource = null;
MessageBox.Show("sorry no data availlable");
}

Best,
Sudheep.



Responses

Posted by: Blessyjees on: 11/14/2011 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Hi,

Verify the column name that you used in the query is same as with the column name in the table including spelling of the column name.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/14/2011 [Member] Starter | Points: 25

Up
0
Down
HI,

with out entering any details into the textbos.if i made click on search button it displays the data.how can i rectify this error.please do the needful.here is my code.

namespace marsweb.imageimpacts
{
public partial class OrderSearch : Form
{
int id1=1;
public OrderSearch()
{
InitializeComponent();
}

private void btn_search_Click(object sender, EventArgs e)
{
//MessageBox .Show ("");
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd = new SqlCommand("select compname,compaddress,invoiceno,orderno,convert(varchar,ondate,105)as [ondate],convert(varchar,invoicedate,105)as [invoicedate],amountstatus,netamount,netvat,tamount from tbl_report2 where orderno=@orderno", con);
con.Open();
cmd.Parameters.AddWithValue("@orderno", txt_orderno.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
con.Close();
}
else
{
//GridView1.Controls.Clear();
GridView1.DataSource = null;
MessageBox.Show("sorry no data availlable");
}

SqlConnection con1 = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd1 = new SqlCommand("select particulars,orderno,quantity,perprice,amount from tbl_report1 where invoiceid=@id1", con1);
cmd1.Parameters.AddWithValue("@id1", id1);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
if (dt1.Rows.Count > 0)
{
GridView2.DataSource = dt1;
con.Close();
}
else
{
GridView2.DataSource = null;
MessageBox.Show("sorry no data availlable");
}


}

private void txt_orderno_TextChanged(object sender, EventArgs e)
{
GridView1.Controls.Clear();
}

private void OrderSearch_Load(object sender, EventArgs e)
{
//GridView1.Controls.Clear();
//txt_orderno.Focus();
}
}
}

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response