Click here to Skip to main content
13,193,405 members (57,434 online)
Rate this:
Please Sign up or sign in to vote.
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:
        public void dtg_sluzby_DefaultValuesNeeded(object sender,
        System.Windows.Forms.DataGridViewRowEventArgs e)
            e.Row.Cells["akce"].Value = 999;
        void vyber_sluzby()

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

but it didn't worked: It juset added a row with other values but column "akce" was empty.
Posted 12-Jul-13 6:53am
Updated 12-Jul-13 7:01am
ThePhantomUpvoter 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.
Marek Šíp 12-Jul-13 13:01pm
Sorry for that, I edited what exactly didn't worked.
ThePhantomUpvoter 12-Jul-13 14:04pm
Probably because your query is not returning any data.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If akce field stores text, try to change your query in this way:
"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[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Advertise | Privacy |
Web01 | 2.8.171017.2 | Last Updated 17 Jul 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100