c# - insert sql commands by textbox -
i created win forms, , wanna insert sql commands , data database. if put query directly code sql commands, ok, if put query textbox have lot of bugs like:
$exception {"could not find stored procedure 'select * uczniowie'."}
system.exception {system.data.sqlclient.sqlexception } {mateuszlab4.connectdb} mateuszlab4.connectdb question "\"select * uczniowie\"" string datatable {} system.data.datatable sqldatareader null system.data.sqlclient.sqldatareader sqlcommand {system.data.sqlclient.sqlcommand} system.data.sqlclient.sqlcommand
here code:
private void buttonsearch_click(object sender, eventargs e) { string query = textboxquery.text; connectdb databasewin = new connectdb("(localdb)\\v11.0", "mat"); datagridviewadvanced.datasource = databasewin.datadownload(query); }
when put string query sql commands (for example string query = "select * students" ) working well. if replaced data textbox sth wrong. give me tips guys?
here class datadownloada:
public datatable datadownload(string question) { datatable datatable = new datatable(); sqldatareader sqldatareader; sqlcommand sqlcommand; sqlcommand = new sqlcommand(question); sqlcommand.connection = this.dbconnection; sqldatareader = sqlcommand.executereader(); datatable.load(sqldatareader); return datatable; }
try code. public datatable datadownload(string question) { using (var ada = new sqldataadapter(question, dbconnection)) { // use dataadapter fill datatable datatable dt = new datatable(); ada.fill(dt); return dt; } }
Comments
Post a Comment