Click to See Complete Forum and Search --> : Asp.net
Tikki
09-15-2003, 01:59 PM
Hello All,
i am new to ASP.NET.
i want to insert a new row into the database(Product table).
i have 3 fields ProdId,ProdName,Price.
i took 3 labels and 3 textboxes on webform1.
and one button. in button click(code behind), i wrote this code to insert my data in to the database. but i am unable to write this code. please let me know the solution ASAP.
---------------------------------
My code in CodeBehind:
private void BtnSave_Click(object sender, System.EventArgs e)
{
// i declared T1,T2 as int and T2 as string in public class WebForm1 : System.Web.UI.Page
T1=this.TxtId.Text;
T2=this.TxtName.Text;
T3=this.TxtPrice.Text;
SqlConnection myConnection = new SqlConnection("server=home-qty00upoqo;database=pubs;user id=sa; pwd=");
string myQuery = "insert into Product Values('&T1'+'"&T2"'+'&T3')";
SqlCommand myCommand = new SqlCommand(myQuery, myConnection);
myConnection.Open();
SqlDataReader myReader;
myReader = myCommand.ExecuteReader();
}
-------------------------------------------
Thanks
PeOfEo
09-15-2003, 04:47 PM
I could probably whip something up for you but it would be in vb. I am not too great with c#, sorry, would you still be interested if it were in vb?
Tikki
09-15-2003, 06:01 PM
Hello PeOfEo,
plese let me know the VB code for my problem.
using that i will try to solve mine
thanks
PeOfEo
09-15-2003, 07:41 PM
Alright well here is what the sql insert statement looks like on a vb asp.net page
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
Dim CmdStr As String
Dim DBInsert As New OleDbCommand
Dim DBConn as OleDbConnection
DBConn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("/pathhere;"))
CmdStr = "Insert Into tablename " _
& "(feild1, feild2,feild3) " _
& "values (@feild1, @feild2, @feild3)"
DBInsert = new OleDbCommand(CmdStr, DBconn)
DBInsert.Parameters.Add("@feild1", OleDbType.VarChar, 255)
DBInsert.Parameters.Add("@feild2", OleDbType.VarChar, 255)
DBInsert.Parameters.Add("@feild3", OleDbType.VarChar, 255)
DBInsert.Parameters("@feild1").Value = Replace(txtfeild1.text, "'", "'")
DBInsert.Parameters("@feild2").Value = Replace(txtfeild2.text, "'", "'")
DBInsert.Parameters("@feild3").Value = Replace(txtfeild3.text, "'", "'")
DBConn.Open()
DBInsert.ExecuteNonQuery()
DBConn.Close()
End Sub
thats what an incert looks like in vb.
The feild1 and @feild1 you would just replace that with the feild name and tablename is the data base table. I did use access for this particular one but thats probably not what your interested in in this code
Tikki
09-16-2003, 01:15 PM
Hello PeOfEo,
Thanks for your help.
i will try with your code and get back to u again.
thanks
PeOfEo
09-16-2003, 07:09 PM
Good luck, the code works for me but if it doesnt work for you copy the error message and Ill take care of it.
Tikki
09-17-2003, 05:59 PM
Hello PeOfEo,
i have a small doubt, if i want to post questions about VB, then which forum is correct to post.
anyway i need some help.
i was trying to develop MTS components.
when i try to add MTS reference i didn't find it in the References. i found MTS 2.0 Admin Type Library instead of
Microsoft Transaction Server Type Library.
what would be the problem?
please try to solve my problem.
Thanks.
PeOfEo
09-17-2003, 08:10 PM
I dont have much knowledge in that area. I really have never used MTS, sorry. Let me just reccomend this, msdn has a whole lot of good webcasts and that is a very good way to learn, you might not be able to find a particular topic as easily, they are not organised that way, but I have just learned so much new matrerial from those.
Tikki
09-18-2003, 11:49 AM
Thanks PeOfEo,
i will do that. one more thing do u know anything about SOAP?
thanks
PeOfEo
09-18-2003, 04:14 PM
Well when I get in the shower I use it.... Well I know what it is, I have a genearal knowledge of what its used for but I dont know enough about it to be of any use to anyone. It does sound like it is something worth learning one day. I would sort of like to get into xml with asp.net sometime, If I could manage to find the free time. I have used xml a little bit here and there but I really only touched on it and know a few things, but I have seen it used before and demonstrated and it looks fun.
Tikki
09-18-2003, 05:18 PM
hello PeOfEo,
thanks for ur response.
i am developing one site on my own using asp, vb.
it deals with online banking(and bank employee information).
i want to develop com components and use them in my site.
please anyone suggest me what kind of components can we develop for my site? i already posted this query and new thread.
please let me know it.
thanks
PeOfEo
09-18-2003, 06:00 PM
Well I dont know asp, I jumped right into asp.net with no asp experience, but I am fluent in vb, but making actual components, I have no experience in that. I am still learning too lol.