I have written the code as below. here problem is that dt
remain null. how to solve thst please tell me.
public partial class Form1 : Form
{
private DataTable DTable;
private DataRow drow;

public Form1()
{
InitializeComponent();
}

private OleDbConnection getConnection()
{
OleDbConnection con=new OleDbConnection
(@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Documents and Settings\Administrator\My
Documents\Visual Studio 2008\Projects\winApp for
Student\winApp for
Student\App_Data\SchooMgnSystem.mdb;Persist Security
Info=True");
return con;
}
private void button1_Click(object sender, EventArgs
e)
{
InsertData();
}

private void InsertData()
{
if (DTable==null)
{
DTable = new DataTable();
DTable.Columns.Add("StudID", typeof(string));
DTable.Columns.Add("StudName", typeof
(string));
DTable.Columns.Add("Address", typeof(string));
drow = DTable.NewRow();
drow[0] = txtStudID.Text;
drow[1] = txtSTudName.Text;
drow[2] = txtAddress.Text;
DTable.Rows.Add(drow);
grdStudent.DataSource = DTable;
}
else
{
drow = DTable.NewRow();
drow[0] = txtStudID.Text;
drow[1] = txtSTudName.Text;
drow[2] = txtAddress.Text;
DTable.Rows.Add(drow);
grdStudent.DataSource = DTable;
}
}

private void button2_Click(object sender, EventArgs
e)
{
string cmdstr;
OleDbCommand cmd;
OleDbConnection con = getConnection();
foreach (DataRow Drow in DTable.Rows)
{
cmdstr = "Insert into Student values('" +
drow[0].ToString() + "','" + drow[1].ToString() + "','"+drow
[2].ToString()+"')";
cmd = new OleDbCommand(cmdstr,con);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}

}
}



I have written the code as below. here problem is that dt remain null. how to solve thst please te..

Answer / Basant Yadav

In your provided code, you are trying to use the DataTable (dt) before it has been initialized. To fix this issue, move the initialization of the DataTable inside the constructor of Form1:

```csharp
public partial class Form1 : Form
{
private DataTable DTable = new DataTable();

public Form1()
{
InitializeComponent();
}

// Rest of your code remains the same
}
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQLServer Errors Interview Questions

How many types of internal joins are there in SQL Server?

0 Answers  


What is Mutex error in Triggers?

1 Answers  


What are row constructors?

1 Answers  


Hi, I am trying to encode data from flatfile and then to decode the encoded data to original form. Procedures that I followed:- 1. Encoded the field 'A_ID' using AES_ENCRYPT(A_ID,'abd') in the expression transformation. The A_ID got encoded in the output table(oracle) 2. To decode this back I used AES_DECRYPT(A_ID,'abd'). But after executing the workflow, I am not getting any data in output. can anybody tell me how to decrypt the encoded data back to original form ??

1 Answers  


write a database figure to implement the master detained relationship.

1 Answers  


definion of tcp

1 Answers   CA,


When do you get "getwmicomexception"?

1 Answers  


What are the required/mandatory parameters that have to be passed with RAISEERROR statement?

1 Answers  


How will you Handle Error in SQL SERVER 2008?

1 Answers  


Difference between Bookmark lookup & RID lookup?

1 Answers  


When you get following error? Error 3154: The backup set holds a backup of a database other than the existing database.

1 Answers  


How to view the error log for any specific instance?

1 Answers  


Categories