paraschhabra96

odbc code

Jul 8th, 2016
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data.Odbc;
  8. using System.Configuration;
  9. using System.Data;
  10. public partial class website1 : System.Web.UI.Page
  11. {
  12. protected void Page_Load(object sender, EventArgs e)
  13. {
  14. OdbcConnection con = new OdbcConnection(
  15. ConfigurationManager.ConnectionStrings["Connname"].ConnectionString);
  16.  
  17. con.Open();
  18.  
  19. String sname, rollno;
  20. sname = TextBox1.Text;
  21. rollno = TextBox2.Text;
  22.  
  23. String query1 = "insert into students values('"+sname+"','"+rollno+"')";
  24.  
  25. OdbcCommand command1 = new OdbcCommand(query1, con);
  26.  
  27. String query = "select * from students";
  28.  
  29. OdbcCommand command = new OdbcCommand(query, con);
  30. OdbcDataReader reader = command.ExecuteReader();
  31. if (reader.HasRows)
  32. {
  33.  
  34. DataTable dt = new DataTable();
  35. dt.Load(reader);
  36.  
  37. foreach (DataRow row in dt.Rows)
  38. {
  39. String name = row[0].ToString();
  40. String no = row[1].ToString();
  41. Response.Write("<h1>" + name +" "+no+ "</h1>");
  42. }
  43.  
  44. }
  45. }
  46. }
Add Comment
Please, Sign In to add comment