471,354 Members | 1,461 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

Update Command in visual studio 2005

hai friends,

I am new to .net programming. I did the inserting data into MS-access database but i couldn't able to perform the update command. I used only textbox and command button for inserting and updating the data. I performed Insert command successfully but i donno y the update command is not working.Pls help.. i ve used all possible update commands. i enclosed all my code( comments also)...

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SUBMIT.Click
'Dim a As Integer
Dim b, d, h, c, g, a As String
Dim d1, f As Date

'Dim cc As Data.CommandBehavior

Dim objConn As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet .OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\New Folder\PMTTracker\DataBase\GcaTAuthentication.mdb" )
Dim objCmd As Data.OleDb.OleDbCommand
Dim objDR As Data.OleDb.OleDbDataReader
Dim edit As Integer
objConn.Open()
Try
a = Convert.ToInt32(TxtSlNo.Text)
b = Txtgrpname.Text.Trim()
c = Txtgrpdesc.Text.Trim()
d = Txtsta.Text.Trim()
d1 = Convert.ToDateTime(Txtcdate.Text.Trim())
g = Txtcby.Text.Trim()
f = Convert.ToDateTime(Txtmdate.Text.Trim())
h = Txtmby.Text.Trim()
'TextBox1.Text = d1
'objCmd = New Data.OleDb.OleDbCommand("update GROUP_MASTER SET (GROUP_NAME ,GROUP_DESC,Status,CREATED_DATE,CREATED_BY,MODIFIE D_DATE,MODIFIED_BY)WHERE GROUP_ID =TxtSlNo.Text.Trim() AND GROUP_NAME =Txtgrpname.Text.Trim() AND GROUP_DESC = Txtgrpdesc.Text.Trim() Status =Txtsta.Text.Trim() AND CREATED_DATE=Txtcdate.Text.Trim() AND CREATED_BY=Txtcby.Text.Trim() AND MODIFIED_DATE=Txtmdate.Text.Trim() AND MODIFIED_BY =Txtmby.Text.Trim() ", objConn)
objCmd = New Data.OleDb.OleDbCommand("UPDATE GROUP_MASTER SET GROUP_NAME ='" & b & "' ,GROUP_DESC ='" & c & "' ,Status ='" & d & "' ,CREATED_BY ='" & f & "' ,MODIFIED_BY='" & h & "' WHERE GROUP_ID ='" & a & "'", objConn)
'objCmd = New Data.OleDb.OleDbCommand("UPDATE GROUP_MASTER SET GROUP_NAME ='" & b & "' WHERE Status ='" & d & "'", objConn)

'UPDATE [GROUP_MASTER] SET [GROUP_NAME] = ?, [GROUP_DESC] = ? WHERE [GROUP_ID] = ? AND [GROUP_NAME] = ? AND [GROUP_DESC] = ?
''objCmd = New Data.OleDb.OleDbCommand("UPDATE GROUP_MASTER SET GROUP_NAME='" + b + "', GROUP_DESC='" + c + "' , Status='" + d + "' ,CREATED_DATE = @d1 , CREATED_BY='" + g + "', MODIFIED_DATE=@f , MODIFIED_BY='" + h + "' WHERE GROUP_ID=@a ", objConn)
'objCmd = New Data.OleDb.OleDbCommand("UPDATE GROUP_MASTER SET GROUP_NAME=@b ,GROUP_DESC=@c , Status=@d ,CREATED_BY=@g ,MODIFIED_BY=@h WHERE [GROUP_ID]=@a", objConn)
'objCmd.Parameters.AddWithValue("@a", a)
'objCmd.Parameters.AddWithValue("@b", b)
'objCmd.Parameters.AddWithValue("@c", c)
'objCmd.Parameters.AddWithValue("@d", d)
''objCmd.Parameters.AddWithValue("@d1", d1)
'objCmd.Parameters.AddWithValue("@g", g)
''objCmd.Parameters.AddWithValue("@f", f)
'objCmd.Parameters.AddWithValue("@h", h)
''objCmd = New Data.OleDb.OleDbCommand("UPDATE GROUP_MASTER SET GROUP_NAME='" & b & "' WHERE GROUP_ID='" & c & "'", objConn)
''objCmd.Parameters.AddWithValue("@a", a)
''objDR = objCmd.ExecuteReader()
''Dim str As String
''str = "UPDATE GROUP_MASTER SET GROUP_NAME='" & b & "' WHERE GROUP_DESC='" & c & "'"
''objCmd = New Data.OleDb.OleDbCommand(str, objConn)
objDR = objCmd.ExecuteReader(System.Data.CommandBehavior.C loseConnection)

''Server.Transfer("Group Maintanance.aspx")

edit = Session("edit")
objCmd = New Data.OleDb.OleDbCommand("select * from GROUP_MASTER where GROUP_ID=@Release", objConn)
objCmd.Parameters.AddWithValue("@Release", edit)
objDR = objCmd.ExecuteReader()
objDR.Read()
TxtSlNo.Text = objDR("GROUP_ID")
Txtgrpname.Text = objDR("GROUP_NAME")
Txtgrpdesc.Text = objDR("GROUP_DESC")
Txtsta.Text = objDR("Status")
Txtcdate.Text = Convert.ToString(objDR("CREATED_DATE"))
Txtcby.Text = Convert.ToString(objDR("CREATED_BY"))
Txtmdate.Text = Convert.ToString(objDR("MODIFIED_DATE"))
Txtmby.Text = Convert.ToString(objDR("MODIFIED_BY"))
objDR.Close()
TextBox1.Text = Txtgrpname.Text
Response.Redirect("Group Maintanance.aspx", False)

Catch ex As Exception
Session("exception") = ex.StackTrace
Session("url") = Request.ServerVariables("HTTP_REFERER")
Response.Redirect("GenException.aspx", False)
End Try
'Response.Redirect("Group Maintanance.aspx")

End Sub




Thanks,

From http://www.developmentnow.com/g/34_2...et-general.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Jun 4 '07 #1
1 5038
Selvakumar,

Check your mdb file permissions and make sure you have "Modify/Read/Write"
set. You probably have "Write" permission but not "Modify" and that's why you
can insert but can't update.

Mike
"Selvakumar" wrote:
hai friends,

I am new to .net programming. I did the inserting data into MS-access database but i couldn't able to perform the update command. I used only textbox and command button for inserting and updating the data. I performed Insert command successfully but i donno y the update command is not working.Pls help.. i ve used all possible update commands. i enclosed all my code( comments also)...

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SUBMIT.Click
'Dim a As Integer
Dim b, d, h, c, g, a As String
Dim d1, f As Date

'Dim cc As Data.CommandBehavior

Dim objConn As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet .OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\New Folder\PMTTracker\DataBase\GcaTAuthentication.mdb" )
Dim objCmd As Data.OleDb.OleDbCommand
Dim objDR As Data.OleDb.OleDbDataReader
Dim edit As Integer
objConn.Open()
Try
a = Convert.ToInt32(TxtSlNo.Text)
b = Txtgrpname.Text.Trim()
c = Txtgrpdesc.Text.Trim()
d = Txtsta.Text.Trim()
d1 = Convert.ToDateTime(Txtcdate.Text.Trim())
g = Txtcby.Text.Trim()
f = Convert.ToDateTime(Txtmdate.Text.Trim())
h = Txtmby.Text.Trim()
'TextBox1.Text = d1
'objCmd = New Data.OleDb.OleDbCommand("update GROUP_MASTER SET (GROUP_NAME ,GROUP_DESC,Status,CREATED_DATE,CREATED_BY,MODIFIE D_DATE,MODIFIED_BY)WHERE GROUP_ID =TxtSlNo.Text.Trim() AND GROUP_NAME =Txtgrpname.Text.Trim() AND GROUP_DESC = Txtgrpdesc.Text.Trim() Status =Txtsta.Text.Trim() AND CREATED_DATE=Txtcdate.Text.Trim() AND CREATED_BY=Txtcby.Text.Trim() AND MODIFIED_DATE=Txtmdate.Text.Trim() AND MODIFIED_BY =Txtmby.Text.Trim() ", objConn)
objCmd = New Data.OleDb.OleDbCommand("UPDATE GROUP_MASTER SET GROUP_NAME ='" & b & "' ,GROUP_DESC ='" & c & "' ,Status ='" & d & "' ,CREATED_BY ='" & f & "' ,MODIFIED_BY='" & h & "' WHERE GROUP_ID ='" & a & "'", objConn)
'objCmd = New Data.OleDb.OleDbCommand("UPDATE GROUP_MASTER SET GROUP_NAME ='" & b & "' WHERE Status ='" & d & "'", objConn)

'UPDATE [GROUP_MASTER] SET [GROUP_NAME] = ?, [GROUP_DESC] = ? WHERE [GROUP_ID] = ? AND [GROUP_NAME] = ? AND [GROUP_DESC] = ?
''objCmd = New Data.OleDb.OleDbCommand("UPDATE GROUP_MASTER SET GROUP_NAME='" + b + "', GROUP_DESC='" + c + "' , Status='" + d + "' ,CREATED_DATE = @d1 , CREATED_BY='" + g + "', MODIFIED_DATE=@f , MODIFIED_BY='" + h + "' WHERE GROUP_ID=@a ", objConn)
'objCmd = New Data.OleDb.OleDbCommand("UPDATE GROUP_MASTER SET GROUP_NAME=@b ,GROUP_DESC=@c , Status=@d ,CREATED_BY=@g ,MODIFIED_BY=@h WHERE [GROUP_ID]=@a", objConn)
'objCmd.Parameters.AddWithValue("@a", a)
'objCmd.Parameters.AddWithValue("@b", b)
'objCmd.Parameters.AddWithValue("@c", c)
'objCmd.Parameters.AddWithValue("@d", d)
''objCmd.Parameters.AddWithValue("@d1", d1)
'objCmd.Parameters.AddWithValue("@g", g)
''objCmd.Parameters.AddWithValue("@f", f)
'objCmd.Parameters.AddWithValue("@h", h)
''objCmd = New Data.OleDb.OleDbCommand("UPDATE GROUP_MASTER SET GROUP_NAME='" & b & "' WHERE GROUP_ID='" & c & "'", objConn)
''objCmd.Parameters.AddWithValue("@a", a)
''objDR = objCmd.ExecuteReader()
''Dim str As String
''str = "UPDATE GROUP_MASTER SET GROUP_NAME='" & b & "' WHERE GROUP_DESC='" & c & "'"
''objCmd = New Data.OleDb.OleDbCommand(str, objConn)
objDR = objCmd.ExecuteReader(System.Data.CommandBehavior.C loseConnection)

''Server.Transfer("Group Maintanance.aspx")

edit = Session("edit")
objCmd = New Data.OleDb.OleDbCommand("select * from GROUP_MASTER where GROUP_ID=@Release", objConn)
objCmd.Parameters.AddWithValue("@Release", edit)
objDR = objCmd.ExecuteReader()
objDR.Read()
TxtSlNo.Text = objDR("GROUP_ID")
Txtgrpname.Text = objDR("GROUP_NAME")
Txtgrpdesc.Text = objDR("GROUP_DESC")
Txtsta.Text = objDR("Status")
Txtcdate.Text = Convert.ToString(objDR("CREATED_DATE"))
Txtcby.Text = Convert.ToString(objDR("CREATED_BY"))
Txtmdate.Text = Convert.ToString(objDR("MODIFIED_DATE"))
Txtmby.Text = Convert.ToString(objDR("MODIFIED_BY"))
objDR.Close()
TextBox1.Text = Txtgrpname.Text
Response.Redirect("Group Maintanance.aspx", False)

Catch ex As Exception
Session("exception") = ex.StackTrace
Session("url") = Request.ServerVariables("HTTP_REFERER")
Response.Redirect("GenException.aspx", False)
End Try
'Response.Redirect("Group Maintanance.aspx")

End Sub




Thanks,

From http://www.developmentnow.com/g/34_2...et-general.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Jun 5 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sharad | last post: by
4 posts views Thread by glenn | last post: by
4 posts views Thread by marti | last post: by
10 posts views Thread by arlef | last post: by
6 posts views Thread by Mohamed Shafiee | last post: by
25 posts views Thread by Tim Zych | last post: by
3 posts views Thread by =?Utf-8?B?THVib21pcg==?= | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.