Click here to Skip to main content
15,893,904 members
Home / Discussions / Database
   

Database

 
GeneralRe: Help Me Pin
Mkanchha15-Apr-07 20:25
Mkanchha15-Apr-07 20:25 
QuestionHelp Me soon Pin
Mkanchha15-Apr-07 19:41
Mkanchha15-Apr-07 19:41 
AnswerRe: Help Me soon Pin
_mubashir15-Apr-07 19:59
_mubashir15-Apr-07 19:59 
GeneralRe: Help Me soon Pin
Mkanchha15-Apr-07 20:02
Mkanchha15-Apr-07 20:02 
Questionwhat is the differenece these two statements Pin
shabonaa15-Apr-07 10:58
shabonaa15-Apr-07 10:58 
AnswerRe: what is the differenece these two statements Pin
kubben15-Apr-07 14:51
kubben15-Apr-07 14:51 
QuestionBook in Stored Procedures [modified] Pin
silvioribeiro15-Apr-07 5:16
silvioribeiro15-Apr-07 5:16 
Questiondatagridview failed to insert record into database Pin
Tony_KT_Lau15-Apr-07 0:59
Tony_KT_Lau15-Apr-07 0:59 
Dear all,
I would like to insert data entered into datagridview(dgv1) into the two fields (with name "code" and "qty") of a database table "stock"
Below is the code. The problem is that the codes run smoothly without error but the data entered into the DGV1 is not inserted into the database:

1. Here are the code at form load. I populate the DGV (with name dgv1) with the existing data of the table 'stock':

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim tbl As New DataTable
tbl.Columns.Add("s_code", GetType(String))
tbl.Columns.Add("S_name", GetType(String))
Dim constr As String = "data source=DADDY-desktop;initial catalog=Fund_System;Integrated Security=True"
Dim sqlstr As String = "select * from stock"
dgv1.DataSource = bs
da = New SqlDataAdapter(sqlstr, constr)
Dim table As New DataTable()
da.Fill(table)
tbl = table
bs.DataSource = tbl
End Sub

2. Here are the codes initiated by a click of a button which was hit after the user has entered code into the datagridview dgv1:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sqlcon As String = "data source=DADDY-desktop;initial catalog=Fund_System;Integrated Security=True"
Dim con As New SqlConnection(sqlcon)
con.Open()
da.InsertCommand = New SqlCommand("insert into stock VALUES (@code, @qty)", con)
Dim pc As SqlParameterCollection
pc = da.InsertCommand.Parameters
pc.Add("@code", SqlDbType.Char, 10, "code")
pc.Add("@qty", SqlDbType.Char, 10, "qty")
Dim tbl As DataTable = New DataTable("cus_table")
da.Fill(tbl)
dgv1.DataSource = tbl
da.Update(tbl)
con.Close()
End Sub

bindingsource bs and DataAdapter da are declare outside of 1 and 2 above, under the Public Class Form1 heading:
Private bs As New BindingSource()
Private da As New SqlDataAdapter()

Dead | X| Dead | X|
Can anybody point out what's wrong with the code?
Thank you very much.

QuestionImporting DataTable In SQL SERVER 2000 Pin
microuser_200014-Apr-07 11:07
microuser_200014-Apr-07 11:07 
AnswerRe: Importing DataTable In SQL SERVER 2000 Pin
Jerry Hammond15-Apr-07 4:46
Jerry Hammond15-Apr-07 4:46 
GeneralRe: Importing DataTable In SQL SERVER 2000 Pin
microuser_200015-Apr-07 8:55
microuser_200015-Apr-07 8:55 
Questionproblems in joining 2 tables together [modified] Pin
aren37214-Apr-07 2:00
aren37214-Apr-07 2:00 
AnswerRe: problems in joining 2 tables together Pin
kubben14-Apr-07 2:26
kubben14-Apr-07 2:26 
GeneralRe: problems in joining 2 tables together Pin
aren37216-Apr-07 18:55
aren37216-Apr-07 18:55 
GeneralRe: problems in joining 2 tables together Pin
kubben17-Apr-07 2:13
kubben17-Apr-07 2:13 
Questionhow can I install my sql file intarget computer? Pin
ali_reza_zareian14-Apr-07 0:54
ali_reza_zareian14-Apr-07 0:54 
Questionis any query (in sql server) that i can export data ? Pin
B.A13-Apr-07 23:28
B.A13-Apr-07 23:28 
AnswerRe: is any query (in sql server) that i can export data ? Pin
Colin Angus Mackay13-Apr-07 23:52
Colin Angus Mackay13-Apr-07 23:52 
Questionhow can Bind ComboBox Pin
Ali el13-Apr-07 22:21
Ali el13-Apr-07 22:21 
AnswerRe: how can Bind ComboBox Pin
Christian Graus13-Apr-07 23:34
protectorChristian Graus13-Apr-07 23:34 
AnswerRe: how can Bind ComboBox Pin
Paul Brower17-Apr-07 10:26
Paul Brower17-Apr-07 10:26 
QuestionStored procedure in sqlserver..... Pin
Member 387988113-Apr-07 18:23
Member 387988113-Apr-07 18:23 
AnswerRe: Stored procedure in sqlserver..... Pin
andyharman16-Apr-07 1:30
professionalandyharman16-Apr-07 1:30 
QuestionGrabing info from table Pin
hahii13-Apr-07 11:16
hahii13-Apr-07 11:16 
AnswerRe: Grabing info from table Pin
Krish - KP16-Apr-07 17:52
Krish - KP16-Apr-07 17:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.