DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   ASP.NET (http://www.daniweb.com/forums/forum18.html)
-   -   Why does it insert NULL values into MySQL DB??? (http://www.daniweb.com/forums/thread65493.html)

vaisakh Dec 22nd, 2006 1:12 am
Why does it insert NULL values into MySQL DB???
 
Dim strInsert As String
Dim cmdInsert As OdbcCommand

Dim cn As OdbcConnection
cn = New _
OdbcConnection(ConfigurationSettings.AppSettings("ConnectionString"))


strInsert = "Insert into realestate.city_master(city_Name)Values(city_name);"
cmdInsert = New OdbcCommand(strInsert, cn)
cmdInsert.Parameters.Add("city_Name", city_name.Text)


cn.Open()
cmdInsert.ExecuteNonQuery()
city_name.Text = ""
cn.Close()

campkev Dec 22nd, 2006 1:45 pm
Re: Why does it insert NULL values into MySQL DB???
 
well, what is the value of city_name.Text when you run the query

hkarthik Jan 12th, 2007 4:28 am
Re: Why does it insert NULL values into MySQL DB???
 
hai,
just try this out.


Quote:

Dim con As OdbcConnection
Dim str As String
Dim cmd As OdbcCommand

con = New OdbcConnection
(ConfigurationSettings.AppSettings("ConnectionString"))

str = "insert into newuser_details values('" & txtusername.Text & "','" & txtpassword.Text & "')"

cmd = New OdbcCommand(str, con)
con.Open()
cmd.ExecuteNonQuery()
con.close()
try this out .it worked for me. the data is getting inserted into MySQL database.

campkev Jan 12th, 2007 7:41 am
Re: Why does it insert NULL values into MySQL DB???
 
that would not be a good way to do it. Opening yourself up to a SQL-injection attack


All times are GMT -4. The time now is 9:42 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC