Following are the code for Visual Basic.
Over here we will assume that connection is opened
HTML Code:
public DataTable GetData(SqlConnection oConnection,string SqlQuery)
{
SqlCommand oCommand;
SqlDataAdapter oDataAdapter;
DataTable dtData=null;
oCommand = new SqlCommand(SqlQuery, oConnection);
oDataAdapter = new SqlDataAdapter(oCommand);
oDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
oDataAdapter.Fill(dtData);
oDataAdapter.Dispose();
oCommand.Dispose();
return dtData;
}
private void SetMaxLengthText()
{
foreach (DataColumn dc in dtDatos.Columns)
{
Control[] control;
control = this.Controls.Find(dc.ColumnName, true);
if (control.Length > 0)
((TextBox)control[0]).MaxLength = dc.MaxLength;
}
}
Bookmarks