Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Now I have coding

string vcode = txtVcode.text;
ddlPurchaseCode.Items.Clear();
string qry = "select PurchaseCode from tblPurchasedInfo where VendorCode='" + vcode + "' and BillNo='" + ddlBillNo.SelectedValue + "' and PurchaseDate='" + ddlPurchaseDate.SelectedValue + "'";

SqlDataReader rds= cls.showDataFromTable(qry);
while (rds.Read())
{
ddlPurchaseCode.Items.Add(rds[0].ToString());
}//end of while
rds.Close();
cls.con.Close();


and Database design

SQL
CREATE TABLE [dbo].[tblPurchasedInfo](
    [PurchaseCode] [varchar](50) NOT NULL,
    [PurchaseDate] [smalldatetime] NOT NULL,
    [EntryDate] [smalldatetime] NOT NULL,
    [BillNo] [varchar](50) NOT NULL,
    [VendorCode] [varchar](50) NOT NULL,
    [Purchaseno] [bigint] IDENTITY(1,1) NOT NULL
) ON [PRIMARY]




The problem is : Data is not loading in ddlPurchaseCode(Dropdownlist)
Can u help what shoul I do.
If I make PurchaseDate as varchar(50) in database, problem will be solved but it will be problem in other pages and transaction. Can u help how to solve.
Posted
Comments
Shubham Choudhary 16-Mar-13 7:03am    
so whats the error!!! can you post it.

This is probably because you are taking values direct and just concatenating them into your command string. This will cause two possible problems:

  1. Your date field will be a string, and thus may not match with what is in the data base.
  2. You are leaving your code open to SQL injection, meaning that your data, or the entire system can be destroyed.

Change your code to use proper parameterised queries on your database, and validate your parameters before using them.
 
Share this answer
 
Comments
Darpan Dahal 16-Mar-13 7:53am    
please can u send a sample how to?
Richard MacCutchan 16-Mar-13 7:55am    
Go and look at some of the SQL articles here on CodeProject.
Hi!!!

convert the dropdownlist selected value
like

C#
DateTime dt;
dt = Convert.ToDateTime(ddl.selectedvalue)";



 void ddlfunction()
    {
        confunction();//your connectionstring
        con.Open();
        MySqlCommand cmd = new MySqlCommand("select PurchaseCode from tblPurchasedInfo where VendorCode='" + vcode + "' and BillNo='" + ddlBillNo.SelectedValue + "' and PurchaseDate='" + dt + "'";)", con);
        MySqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {

            ddl.Items.Add(dr["Column_Name"].ToString());

        }
        con.Close();



I write this code in notepad so make correction on it!!
 
Share this answer
 
v2
SELECT CONVERT(varchar(20),PurchaseDate,108) as Date


use following query in your code

string qry = "select PurchaseCode from tblPurchasedInfo where VendorCode='" + vcode + "' and BillNo='" + ddlBillNo.SelectedValue + "' and SELECT CONVERT(varchar(20),PurchaseDate,108) as Date='" + ddlPurchaseDate.SelectedValue + "'";

this will definately solve your problem.
 
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