I am trying to read data from the database, then populate the datatable before binding to GridView.
When I run the application, it produces these erors:
Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'PrescriptionNumber'.
Invalid column name 'PrescriptionNumber'.
Invalid column name 'DrugCode'.
Invalid column name 'PrescriptionDate'.
Invalid column name 'PaymentStatus'.
Invalid column name 'AmountPaidFrom'.
Source Error:
Line 34: cmd.Connection = con;
Line 35: con.Open();
Line 36: using (SqlDataReader reader = cmd.ExecuteReader())
Line 37: {
Line 38: if (reader.HasRows)
Here is the markup:
<asp:GridView ID="grdpayment" runat="server" Width="876px"
AutoGenerateColumns="False" CellPadding="4" GridLines="Horizontal"
BackColor="White" BorderColor="#336666" BorderStyle="Double"
BorderWidth="3px" style="margin-right: 288px"
onselectedindexchanged="grdpayment_SelectedIndexChanged">
<FooterStyle BackColor="White" ForeColor="#333333" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#333333" />
<SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#487575" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#275353" />
</asp:GridView>
Did any want know am am doing wrong? here is my table script:
CREATE TABLE [dbo].[Payment](
[PrescriptionNumber] [varchar](50) NOT NULL,
[TreatmentCode] [varchar](50) NOT NULL,
[DrugCode] [varchar](50) NOT NULL,
[PrescriptionDate] [date] NOT NULL,
[DrugQuantity] [int] NOT NULL,
[PaymentStatus] [varchar](50) NOT NULL,
[AmountPaid] [money] NOT NULL
) ON [PRIMARY]
C# Method that read data from the data:
public void makepayment(string prescriptionValue)
{
DataTable storedata = new DataTable();
string _connection = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
SqlConnection con = new SqlConnection(_connection);
string sqlquery =
"Select PrescriptionNumber,DrugCode,PrescriptionDate,PaymentStatus,AmountPaid"
+ "From Payment where PrescriptionNumber='" + prescriptionValue + "'";
SqlCommand cmd = new SqlCommand(sqlquery,con);
SqlDataAdapter adapt = new SqlDataAdapter(cmd);
adapt.Fill(storedata);
grdpayment.DataSource = storedata;
grdpayment.DataBind();
}
i call the method like this:
protected void btnsearchprescripitionnum_Click(object sender, EventArgs e)
{
if (txtprescriptionnum.Text == "")
{
checkval.Text = "Enter PriscriptionNumber";
}
else
{
makepayment(txtprescriptionnum.Text.ToString());
}
}