|
Thanks Soren for your helpful reply.
Wow I just realised it is xmas on the other side of the planet. Happy xmas.
Yeah I think conventions are contextual. 'When in CodeProjectLand do as CodeProjectarians do'.
|
|
|
|
|
Jibba Jabba wrote: Yeah I think conventions are contextual. 'When in CodeProjectLand do as CodeProjectarians do'. I wouldn't say that, I see that behavior all the time, referring to the CP survey just seemed like an obvious thing to do.
Jibba Jabba wrote: Wow I just realised it is xmas on the other side of the planet. Happy xmas. Merry Christmas to you too.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
"I wouldn't say that, I see that behavior all the time, referring to the CP survey just seemed like an obvious thing to do."
Thanks, helpful reply. And I agree.
In my solution to the exercise, not only was it obvious, I stated (on the other forum) that the hypothetical pizza shop owner wanted it. Happy user? That's gotta be good.
Appreciate your experience and thoughts.
|
|
|
|
|
I see it both ways many times. It all depends on what your needs are. If you want to force a selection then don't have one selected by default.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Thanks for your replies.
I just found the vote helpful button. Was a bit slow, nOOb issues.
|
|
|
|
|
You're welcome.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Just adding some more thoughts on this.
If an api required a default selection based on this said convention, and you chose not to make your own buttons, then applying this to the pizza example, I'd have to have a default "no selection" choice, which is redundant and I think absurd. And then force an alternative selection.
Unusual convention I think. Once again thanks for your thoughts on this.
|
|
|
|
|
How to start working with asp.net web application
|
|
|
|
|
Get a book and start working through the examples. The do some online tutorials, then define the project you want to do and find some examples and tutorials on or close to the subject.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
In addition to Mycroft's suggestion, you could also go to http://www.asp.net/[^]. Also note that there is a specific forum for ASP.NET questions.
Veni, vidi, abiit domum
|
|
|
|
|
Hello. I did the following:
Update-delete-insert-save in the dataset.
not in the database.
And now i want my dataset to affect the database(sql server)
without using DataAdapter.(It's a method for lazy people)
How can i do that?
Any help is appreciated.
Thank you
|
|
|
|
|
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Try
Dim dv As DataView = New DataView(_DataSet.Tables(0))
If ComboBox1.Text = "Deleted" Then
dv.RowStateFilter = DataViewRowState.Deleted
Me.DataGridView2.DataSource = dv
Me.DataGridView2.Refresh()
ElseIf ComboBox1.Text = "Added" Then
dv.RowStateFilter = DataViewRowState.Added
Me.DataGridView2.DataSource = dv
Me.DataGridView2.Refresh()
ElseIf ComboBox1.Text = "Unchanged" Then
dv.RowStateFilter = DataViewRowState.Unchanged
Me.DataGridView2.DataSource = dv
Me.DataGridView2.Refresh()
ElseIf ComboBox1.Text = "None" Then
dv.RowStateFilter = DataViewRowState.None
Me.DataGridView2.DataSource = dv
Me.DataGridView2.Refresh()
ElseIf ComboBox1.Text = "Current Rows" Then
dv.RowStateFilter = DataViewRowState.CurrentRows
Me.DataGridView2.DataSource = dv
Me.DataGridView2.Refresh()
ElseIf ComboBox1.Text = "OriginalRows" Then
dv.RowStateFilter = DataViewRowState.OriginalRows
Me.DataGridView2.DataSource = dv
Me.DataGridView2.Refresh()
ElseIf ComboBox1.Text = "Modified Current" Then
dv.RowStateFilter = DataViewRowState.ModifiedCurrent
Me.DataGridView2.DataSource = dv
Me.DataGridView2.Refresh()
ElseIf ComboBox1.Text = "Modified Original" Then
dv.RowStateFilter = DataViewRowState.ModifiedOriginal
Me.DataGridView2.DataSource = dv
Me.DataGridView2.Refresh()
ElseIf ComboBox1.Text = "Modified Current" Then
dv.RowStateFilter = DataViewRowState.ModifiedCurrent
Me.DataGridView2.DataSource = dv
Me.DataGridView2.Refresh()
End If
Catch ex As Exception
MsgBox("No record were Modified")
End Try
End Sub
modified 20-Dec-13 4:37am.
|
|
|
|
|
Ugly, ugly, ugly code. Did you try it?? Did it update the database?? Probably not.
|
|
|
|
|
I updated it . Can you check it Please?
|
|
|
|
|
Nothing changed. It's still very ugly and has no code at all for updating the database.
If you want to manually rewrite the code that you find in the DataAdapter, that's your choice. I don't see why you're not using a DataAdapter, but then again, I don't what you're SELECT query looks like either.
The Refresh method only redraws the grid on screen. It does NOT tell anything to touch the database.
|
|
|
|
|
Clean up your code.
Use ElseIf .
|
|
|
|
|
Member 10388494 wrote: And now i want my dataset to affect the database(sql server) without using DataAdapter.(It's a method for lazy people) Only if you consider .NET to be a language for those who are to lazy to write assembler
There's nothing wrong with using a DataAdapter
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
No no no. I didn't mean it in a bad way. I am just trying to find how to write in database without the DataAdapter.
Any idea?
I am starting to get a bit desperate :/
|
|
|
|
|
Well, if you want to replicate what the DataAdapter does, you'll have to:
- Create a
DbCommand and relevant parameters to delete a row; - Call
GetChanges(DataRowState.Deleted) on the DataTable ; - Iterate through the returned rows, assigning the relevant values to the parameters and executing the command to delete the row from the database;
- Create a
DbCommand and relevant parameters to update a row; - Call
GetChanges(DataRowState.Modified) on the DataTable ; - Iterate through the returned rows, assigning the relevant values to the parameters and executing the command to update the row in the database;
- Create a
DbCommand and relevant parameters to insert a new row; - Call
GetChanges(DataRowState.Added) on the DataTable ; - Iterate through the returned rows, assigning the relevant values to the parameters and executing the command to insert the row in the database;
If you're dealing with multiple tables, you'll need to ensure that you handle them in the correct order to make sure that you don't try to insert a child row before the related parent row.
If you want to add concurrency, you'll need to pass the original values of the relevant columns to your update and delete procedures. Use row[column, DataRowVersion.Original] to read the original value.
You'll probably want to wrap everything up in a DbTransaction to make sure the changes are atomic.
In short, it's a lot of work that you don't really need to do, as the DbDataAdapter already does it for you.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That's a big help. Thank you Richard Deeming
And Dave Kreskowiak, I am sorry if the word "lazy". It was inappropriate. But i am still learning. so I was trying to find a way to do so.
Thank you for your time.
|
|
|
|
|
Hello again. Thanks again Richard Deeming.
I DID IT
I found a simpler way to to what i asked before.
I realised that there is no need for the datatable. I already have a Dataset. so I can do the following:
Here i clear the textboxes in order to insert new data..
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
_isadded = True
txtAddress.Text = ""
txtName.Text = ""
txtEmail.Text = ""
txtserial.Text = ""
End Sub
Here: If _isadded = False: I am updating an existing record.
If _isadded = True I am inserting a new record.
Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
If _isadded = False Then
_DataSet.Tables(0).Rows(txtCurrent.Text - 1).Item("Name") = txtName.Text
_DataSet.Tables(0).Rows(txtCurrent.Text - 1).Item("Address") = txtAddress.Text
_DataSet.Tables(0).Rows(txtCurrent.Text - 1).Item("Email") = txtEmail.Text
Else
txtCount.Text = CStr(CInt(txtCount.Text) + 1)
txtCurrent.Text = txtCount.Text
Dim _dr As DataRow = _DataSet.Tables(0).NewRow
_dr.Item(1) = txtCurrent.Text
_dr.Item(2) = txtName.Text
_dr.Item(3) = txtEmail.Text
_dr.Item(4) = txtAddress.Text
_DataSet.Tables(0).Rows.Add(_dr)
End If
As for the database..That is what i did:
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
DataGridView2.Columns.Item(0).Visible = False
If _isdeleted = True Then
Dim cmd As New SqlCommand
If _cn.State = ConnectionState.Closed Then _cn.Open()
cmd.Connection = _cn
cmd.CommandText = "delete from tblcustomer where serial = " & Val(txtserial.Text)
cmd.ExecuteNonQuery()
txtCurrent.Text = (txtCount.Text) - 1
RefreshData(True)
ElseIf _isadded = False Then
Dim strconnection As String = "Data Source=ELIANE-VAIO\SQLEXPRESS;Initial Catalog=DatabaseConnection;Integrated Security=True;"
Dim _cn As SqlConnection = New SqlConnection(strconnection)
Dim cmd As New SqlCommand
_cn.Open()
cmd.CommandText = "update tblCustomer set ID=@ID, Name=@Name, Email=@Email, Address=@Address where serial = @serial"
cmd.Connection = _cn
cmd.Parameters.AddWithValue("@ID", Me.txtIDD.Text)
cmd.Parameters.AddWithValue("@Name", Me.txtName.Text)
cmd.Parameters.AddWithValue("@Email", Me.txtEmail.Text)
cmd.Parameters.AddWithValue("@Address", Me.txtAddress.Text)
cmd.Parameters.AddWithValue("@serial", Me.txtserial.Text)
cmd.ExecuteNonQuery()
Else
Try
Dim strconnection As String = "Data Source=eliane-vaio\sqlexpress;Initial Catalog=DatabaseConnection;Integrated Security=True;"
Dim _cn As SqlConnection = New SqlConnection(strconnection)
Dim cmd As New SqlCommand
_cn.Open()
cmd.CommandText = "INSERT INTO tblCustomer([ID],[Name], [Email], [Address]) VALUES (@ID, @Name, @Email, @Address) select @@IDENTITY;"
cmd.Connection = _cn
cmd.Parameters.AddWithValue("@ID", Me.txtCurrent.Text)
cmd.Parameters.AddWithValue("@Name", Me.txtName.Text)
cmd.Parameters.AddWithValue("@Email", Me.txtEmail.Text)
cmd.Parameters.AddWithValue("@Address", Me.txtAddress.Text)
txtserial.Text = cmd.ExecuteScalar.ToString()
Me._DataAdapter.Fill(Me._DataSet)
cmdRequery.PerformClick()
cmdLast.PerformClick()
Catch ex As Exception
MsgBox("Press add before you continue")
End Try
End If
End Sub
|
|
|
|
|
|
Member 10388494 wrote: I didn't mean it in a bad way
Yes you did. What you said about "lazy" has no other interpretation.
Member 10388494 wrote: I am just trying to find how to write in database without the DataAdapter
WHY? What you're doing is exactly what the DataAdapter was designed to do! Ok, fine. While you're sitting there re-inventing the DataAdapter, the rest of us "lazy" people will use the DataAdapter, be done with the code and have moved on to other parts of the project completing them before you do.
|
|
|
|
|
Hello. I have this code to update A RECORD IN sql server . But it's giving me an error:
wrong syntax near Where.
Any help Please?
Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
Dim strconnection As String = "Data Source=ELIANE-VAIO\SQLEXPRESS;Initial Catalog=DatabaseConnection;Integrated Security=True;"
Dim _cn As SqlConnection = New SqlConnection(strconnection)
Dim cmd As New SqlCommand
_cn.Open()
Dim strsql As String
strsql = "update tblcustomer set "
strsql = strsql & " ID = '" & txtCurrent.Text & "', "
strsql = strsql & " name = '" & txtName.Text & "', "
strsql = strsql & " email = '" & txtEmail.Text & "', "
strsql = strsql & " address = '" & txtAddress.Text & "', "
strsql = strsql & " deptid = " & cbDept.SelectedValue
strsql = strsql & " where serial = " & Val(txtserial.Text)
cmd.CommandText = strsql
cmd.Connection = _cn
cmd.ExecuteNonQuery()
cmdRequery.PerformClick()
End Sub
serial is autoincremented in sql server.
|
|
|
|
|
You really shouldn't build your SQL like that. If I were you, I would consider using parameterized queries so that you can avoid SQL Injection attacks.
|
|
|
|