Click here to Skip to main content
15,849,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys, Im trying to make my datagridview automatically fill column "akce" with value from textbox zakce.Text can you propose me any idea? I tried this:
C#
public void dtg_sluzby_DefaultValuesNeeded(object sender,
System.Windows.Forms.DataGridViewRowEventArgs e)
{

    e.Row.Cells["akce"].Value = 999;

}
void vyber_sluzby()
{
    try
    {



        da1 = new SqlDataAdapter("select * from zajsluz WHERE akce=" + zakce.Text, spojeni);
        sqlCommandBuilder = new SqlCommandBuilder(da1);
        dt = new DataTable();
        da1.Fill(dt);
        dtg_sluzby.DataSource = dt;

but it didn't worked: It juset added a row with other values but column "akce" was empty.
Posted
Updated 12-Jul-13 8:01am
v2
Comments
[no name] 12-Jul-13 12:59pm    
"it didn't worked" does not mean anything to anyone but you. You have just performed the equivalent of calling your mechanic on the phone, telling him/her "car broke" and walking away. Do you really think that your mechanic can tell you what is wrong with your car then? What did not work? Did your code run at all? Did you code run but your cat ran away from home? You have to tell us.... we cannot see your screen or read your mind.
mareksip 12-Jul-13 13:01pm    
Sorry for that, I edited what exactly didn't worked.
[no name] 12-Jul-13 14:04pm    
Probably because your query is not returning any data.

1 solution

If akce field stores text, try to change your query in this way:
SQL
"select * from zajsluz WHERE akce='" + zakce.Text + "'"

But remember, building queries in code behind you are exposed on SQL Injection attack[^] ;(

Rather than building queries in code behind, use stored procedures[^].

Walkthrough: Using Only Stored Procedures (C#)[^] - follow related links
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET[^]
 
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