Click here to Skip to main content
16,004,887 members
Home / Discussions / Database
   

Database

 
QuestionSQL Sort & Group Pin
munklefish19-Mar-06 8:56
munklefish19-Mar-06 8:56 
AnswerRe: SQL Sort & Group Pin
nguyenvhn19-Mar-06 23:36
nguyenvhn19-Mar-06 23:36 
GeneralRe: SQL Sort & Group Pin
munklefish20-Mar-06 6:10
munklefish20-Mar-06 6:10 
GeneralRe: SQL Sort & Group Pin
nguyenvhn20-Mar-06 21:05
nguyenvhn20-Mar-06 21:05 
GeneralRe: SQL Sort & Group Pin
munklefish21-Mar-06 0:07
munklefish21-Mar-06 0:07 
GeneralRe: SQL Sort & Group Pin
nguyenvhn21-Mar-06 23:11
nguyenvhn21-Mar-06 23:11 
GeneralRe: SQL Sort & Group Pin
munklefish22-Mar-06 0:19
munklefish22-Mar-06 0:19 
QuestionUpdating Database ... Its Urgent Pin
Amit R19-Mar-06 4:15
Amit R19-Mar-06 4:15 
Hello Members,

I am facing problem in updating the dataset (Database). I have tried number of things(all may b wrong). Can u please help me. This is the code

Dim bm As BindingManagerBase<br />
    Dim currentrow As Integer<br />
    Dim ds As New DataSet()<br />
    Dim bval As Boolean<br />
    Dim dt As DataTable<br />
    Dim dr As DataRow<br />
    Dim cn As SqlConnection = New SqlClient.SqlConnection("Data Source = ; Database = Pubs;uid=sa")<br />
    Dim da As SqlDataAdapter = New SqlClient.SqlDataAdapter("Select * from publishers", cn)<br />
    Dim flag As Integer<br />
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
<br />
        da.Fill(ds, "publishers")<br />
        bm = Me.BindingContext(ds.Tables("Publishers"))<br />
        bm.Position = 0<br />
        Loaddataincontrols()<br />
        Setbuttons(True)<br />
        LockTbox()<br />
    End Sub<br />
<br />
Public Sub Loaddataincontrols()<br />
        TextBox1.Text = ds.Tables("Publishers").Rows(bm.Position)("Pub_id").ToString<br />
        TextBox2.Text = ds.Tables("Publishers").Rows(bm.Position)("Pub_name").ToString<br />
        TextBox3.Text = ds.Tables("Publishers").Rows(bm.Position)("city").ToString<br />
        TextBox4.Text = ds.Tables("publishers").Rows(bm.Position)("State").ToString<br />
        TextBox5.Text = ds.Tables("Publishers").Rows(bm.Position)("Country").ToString<br />
    End Sub<br />
<br />
Private Sub CmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdAdd.Click<br />
        'dr = (ds.Tables("Publishers").NewRow)<br />
        Setbuttons(False)<br />
        UnLockTbox()<br />
        ClearControls()<br />
        flag = 1<br />
        'LoaddatainDataset()<br />
        'ds.Tables("Publishers").Rows.Add(dr)<br />
    End Sub<br />
    Public Sub UnLockTbox()<br />
        TextBox1.ReadOnly = False<br />
        TextBox2.ReadOnly = False<br />
        TextBox3.ReadOnly = False<br />
        TextBox4.ReadOnly = False<br />
        TextBox5.ReadOnly = False<br />
    End Sub<br />
    Public Sub ClearControls()<br />
        TextBox1.Text = ""<br />
        TextBox2.Text = ""<br />
        TextBox3.Text = ""<br />
        TextBox4.Text = ""<br />
        TextBox5.Text = ""<br />
    End Sub<br />
    Public Sub LoaddatainDataset()<br />
        dr("Pub_id") = TextBox1.Text<br />
        dr("Pub_name") = TextBox2.Text<br />
        dr("City") = TextBox3.Text<br />
        dr("State") = TextBox4.Text<br />
        dr("Country") = TextBox5.Text<br />
    End Sub<br />
<br />
    Private Sub CmdModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdModify.Click<br />
        UnLockTbox()<br />
        flag = 3<br />
        Setbuttons(False)<br />
        '   dr = ds.Tables("Publishers").Rows(bm.Position)<br />
        '  dr.BeginEdit()<br />
        ' LoaddatainDataset()<br />
        ' dr.EndEdit()<br />
        'Setbuttons(False)<br />
        'da.Update(ds, "Publishers")<br />
        'da.Fill(ds)<br />
        'bm.Position = 0<br />
    End Sub<br />
<br />
    Private Sub cmdRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRemove.Click<br />
        '     dr = ds.Tables("Publishers").Rows(bm.Position)<br />
        '    ds.Tables("Publishers").Rows.Remove(dr)<br />
        dt = ds.Tables("Publishers")<br />
        dr = dt.Rows.Find(TextBox1.Text)<br />
        flag = 2<br />
    End Sub<br />
<br />
    Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click<br />
        Dim da As SqlDataAdapter = New SqlClient.SqlDataAdapter("Select * from publishers", cn)<br />
        If flag = 1 Then<br />
            dt = ds.Tables("Publishers")<br />
            dr = dt.NewRow()<br />
            LoaddatainDataset()<br />
            dt.Rows.Add(dr)<br />
        ElseIf flag = 2 Then<br />
            dr.Delete()<br />
        ElseIf flag = 3 Then<br />
            dt = ds.Tables("Publishers")<br />
            dr = dt.Rows.Find(TextBox1.Text)<br />
            dr.BeginEdit()<br />
            LoaddatainDataset()<br />
            dr.EndEdit()<br />
        End If<br />
        flag = 0<br />
        CreateCommandAndUpdate("Data Source = ; Database = Pubs;uid=sa", "Select * from Publishers")<br />
        da.Fill(ds)<br />
<br />
<br />
        '        LoaddatainDataset()<br />
        '       da.Update(ds, "Publishers")<br />
        '      da.Fill(ds)<br />
        bm.Position = 0<br />
        Loaddataincontrols()<br />
        Setbuttons(True)<br />
    End Sub<br />
<br />
    Public Function CreateCommandAndUpdate( _<br />
    ByVal connectionString As String, _<br />
    ByVal queryString As String) As DataSet<br />
        da.SelectCommand = New SqlCommand(queryString, cn)<br />
<br />
        Dim commandBuilder As SqlCommandBuilder = _<br />
            New SqlCommandBuilder(da)<br />
<br />
<br />
<br />
        ' Code to modify the data in the DataSet here. <br />
<br />
        ' Without the OleDbCommandBuilder this line would fail.<br />
        da.Update(ds)<br />
        da.Fill(ds)<br />
        'End Using<br />
        CreateCommandAndUpdate = ds<br />
    End Function


It gave me these errors

An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll

Additional information: Update requires a valid InsertCommand when passed DataRow collection with new rows.


An unhandled exception of type 'System.Data.MissingPrimaryKeyException' occurred in system.data.dll

Additional information: Table doesn't have a primary key.

Please Help....

Regards,


Amit
QuestionSending Message to user editing record Pin
Amit R19-Mar-06 1:04
Amit R19-Mar-06 1:04 
QuestionIs there any Sql command to Backup and restore sql database? Pin
anant iyer18-Mar-06 21:02
anant iyer18-Mar-06 21:02 
AnswerRe: Is there any Sql command to Backup and restore sql database? Pin
Danilo Corallo19-Mar-06 0:56
Danilo Corallo19-Mar-06 0:56 
AnswerRe: Is there any Sql command to Backup and restore sql database? Pin
Beemen19-Mar-06 4:49
Beemen19-Mar-06 4:49 
GeneralRe: Is there any Sql command to Backup and restore sql database? Pin
anant iyer20-Mar-06 23:20
anant iyer20-Mar-06 23:20 
AnswerRe: ADO.Net Example Pin
anant iyer18-Mar-06 20:55
anant iyer18-Mar-06 20:55 
QuestionRow intervall Pin
nixter99918-Mar-06 1:53
nixter99918-Mar-06 1:53 
AnswerRe: Row intervall Pin
goyal manish19-Mar-06 17:44
goyal manish19-Mar-06 17:44 
QuestionHow do you import a CSV file into MS SQL? Pin
mcljava17-Mar-06 18:47
mcljava17-Mar-06 18:47 
AnswerRe: How do you import a CSV file into MS SQL? Pin
Mike Dimmick18-Mar-06 11:17
Mike Dimmick18-Mar-06 11:17 
AnswerRe: How do you import a CSV file into MS SQL? Pin
Jorge Novo18-Mar-06 15:19
Jorge Novo18-Mar-06 15:19 
GeneralRe: How do you import a CSV file into MS SQL? Pin
mcljava19-Mar-06 18:02
mcljava19-Mar-06 18:02 
QuestionCrystal Reports.NET, Push method, Login failed Pin
Glenn E. Lanier II17-Mar-06 9:27
Glenn E. Lanier II17-Mar-06 9:27 
QuestionBLOB image data conversion Pin
marianguru17-Mar-06 8:45
marianguru17-Mar-06 8:45 
QuestionADO.NET 2.0 best online comprehensive source for information Pin
LuluSailor17-Mar-06 7:03
LuluSailor17-Mar-06 7:03 
AnswerRe: ADO.NET 2.0 best online comprehensive source for information Pin
Dave Kreskowiak17-Mar-06 16:45
mveDave Kreskowiak17-Mar-06 16:45 
QuestionOleDbConnection & Network drive Pin
hasanali0017-Mar-06 4:10
hasanali0017-Mar-06 4:10 

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.