Opet ja ;)
Pogledala sam ove linkove, ali opet ne mogu da se snadjem.
Nasla sam na netu neki kod, ali imam neke greske, pa mi pomoglo ako neko moze da mi kaze kako da ih otklonim i da li je uopste ovaj kod dobar
Code:
Private ConnectionString As String = "Integrated Security=SSPI;" + "Initial Catalog=;" + "Data Source=localhost;"
Private reader As SqlDataReader = Nothing
Private conn As SqlConnection = Nothing
Private cmd As SqlCommand = Nothing
Private AlterTableBtn As System.Windows.Forms.Button
Private sql As String = Nothing
Private Sub ExecuteSQLStmt(ByVal sql As String)
Try ' Open the connection
If conn.State = ConnectionState.Open Then
conn.Close()
End If
ConnectionString = "Integrated Security=SSPI;" + "Initial Catalog=baza;" + "Data Source=localhost;"
conn.ConnectionString = ConnectionString
conn.Open()
cmd = New SqlCommand(sql, conn)
cmd.ExecuteNonQuery()
Catch ae As SqlException
MessageBox.Show(ae.Message.ToString())
End Try
End Sub 'ExecuteSQLStmt
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
If conn.State = ConnectionState.Open Then
conn.Close()
End If
ConnectionString = "Integrated Security=SSPI;" + "Initial Catalog=baza;" + "Data Source=localhost;"
conn.ConnectionString = ConnectionString
conn.Open()
cmd.ExecuteNonQuery()
' Adding records the table
sql = "INSERT INTO kalkulator(id_kalkulator, operacija, rezultat, datum) " + "VALUES (1, sabiranje', '50', '01.07.2010' ) "
cmd = New SqlCommand(sql, conn)
cmd.ExecuteNonQuery()
Catch ae As SqlException
MessageBox.Show(ae.Message.ToString())
End Try
End Sub
Htela sam da probam sa fiksnim podacima, pa ako uspe upisivanje da ubacim sadrzaj iz tekstualnih polja. medjutim kada pokrenem ovakav kod pojavljuje mi se sledeca greska - Object reference not set to an instance of an object....Tips: use the “new” keyword to create an object instance.
S obzirom da sam laik, potrebna mi je pomoc i za ovako nesto.