Click here to Skip to main content
15,892,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public static Boolean Insert_Imp_Case(int Imp_Case_Id, string Imp_Case_Number, string Imp_Case_Date,
           string Case_Ref_No, string Bl_Number, string Bl_Type, string POL, string POD, string PLD, string Client_Coa,
            string Case_type)
        {
           
            StringBuilder var1 = new StringBuilder();
            var1.Append("INSERT INTO Imp_Case_Header \n");
            var1.Append("            (Imp_Case_Id, \n");
            var1.Append("             Imp_Case_Number, \n");
            var1.Append("             Imp_Case_Date, \n");
            var1.Append("             Case_Ref_No, \n");
            var1.Append("             Bl_Number, \n");
            var1.Append("             Bl_Type, \n");
            var1.Append("             POL, \n");
            var1.Append("             PLD , \n");
            var1.Append("             POD , \n");
            var1.Append("             Client_Coa, \n");
            var1.Append("             Sustring(Case_type,1,1))");

----------------------------------------------------------------------



            var1.Append("VALUES      ( '" + Imp_Case_Id + "', \n");
            var1.Append("              '" + Imp_Case_Number.Replace("'", "''") + "', \n");
            var1.Append("              '" + Imp_Case_Date + "', \n");
            var1.Append("              '" + Case_Ref_No + "', \n");
            var1.Append("              '" + Bl_Number + "', \n");
            var1.Append("              '" + Bl_Type + "', \n");
            var1.Append("              '" + POL + "', \n");
            var1.Append("              '" + PLD + "', \n");
            var1.Append("              '" + POD + "', \n");
            var1.Append("              '" + Client_Coa + "', \n");
            var1.Append("              '" + Case_type + "') ");


Case_Type is drop down list I want to pick the first letter and then insert into table but i am not getting the result.
Posted
Updated 24-Jan-14 18:12pm
v2

C#
string ctypeChar = string.Empty;

if (Case_type.SelectedItem != null && !string.IsNullOrEmpty(Case_type.SelectedItem.ToString())
    cTypeChar = Case_type.SelectedItem.ToString()[0];


Then replace Case_type in your append with cTypeChar.

But...

You are really making your query wrong, you should be using parameters[^]. Read up on how to use parameterized queries so you don't subject yourself to SQL injection attacks.

[Edit]
Just read a little closer, you are passing Case_type as a string into the function. You can use this code to calculate the Case_type value to pass to the function. I wrote the code as if Case_type was the actual combobox.
 
Share this answer
 
v2
Do these changes
change from
C#
var1.Append(" Sustring(Case_type,1,1))");

To
C#
var1.Append("Case_type))");


and add this line

C#
 Case_type = Case_type.Substring(0, 1);
  var1.Append(" '" + Case_type + "') ");
 
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