datagridview - vb.net SQL causing - "Must declare the scalar variable " -
i've been stuck on error while, in vb.net trying connect sql , pull data table within day, using parameters this, datetimepicker - data saved sql in custom datetime format dd/mm/yyyy hh:mm:ss
,
when execute code
"must declare scalar variable "@line"
when remove code " [line] = @line , date >= @startdata , date < @enddata " works shows data without date range should.
connect() datagridview1.autogeneratecolumns = true cmd.parameters.clear() cmd.commandtext = @"select board, defect, date, detail_x, detail_y, detail_width, detail_height [sqlccmdefects] [line] = @line , date >= @startdata , date < @enddata"; cmd.parameters.add("@line", sqldbtype.varchar, 30).value = form1.line.text cmd.parameters.add("@startdata", sqldbtype.datetime).value = datetimepicker1.value cmd.parameters.add("@enddata", sqldbtype.datetime).value = datetimepicker2.value cmd.executescalar() dim dataadapter1 = new sqldataadapter(cmd.commandtext, con.connectionstring) dim table1 new datatable() table1.locale = system.globalization.cultureinfo.invariantculture dataadapter1.fill(table1) me.bindingsource1.datasource = table1 datagridview1.datasource = bindingsource1 disconnect()
all blank datagridview scalar error.
there looks couple of issues in code posted, try this:
'sql connection dim sqlcon new sqlconnection("server=.;database=dummy;trusted_connection=true;") 'sql command dim sqlcmd new sqlcommand("", sqlcon) sqlcmd.commandtext = "select board, defect, date, detail_x, detail_y, detail_width, detail_height [sqlccmdefects] [line] = @line , date >= @startdata , date < @enddata" 'sql command params sqlcmd.parameters.add("@line", sqldbtype.varchar, 30).value = "whatever" sqlcmd.parameters.add("@startdata", sqldbtype.datetime).value = "2015-07-21" sqlcmd.parameters.add("@enddata", sqldbtype.datetime).value = "2015-07-23" 'data adapters dim dataadapter1 = new sqldataadapter(sqlcmd) dim table1 new datatable() 'not sure does? table1.locale = system.globalization.cultureinfo.invariantculture 'attach gv dataadapter1.fill(table1) datagridview1.autogeneratecolumns = true bindingsource1.datasource = table1 datagridview1.datasource = bindingsource1
Comments
Post a Comment