vs2005里给一个button控件添加sql操作语句的最简单方法是怎么样?
大伙指点一下·~
就是一个button控件 点击之后操作一条sql语句 如果按照一般的方法在事件里声明数据库连接字符串 sql语句 等等很繁琐 我想vs2005应该有自动生成sql语句的功能吧
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim sqlstring As String
Dim sqlcmd As OleDbCommand
Dim sqlcon As OleDbConnection //如何使用如下数据源里的ConnectionStrings ?
sqlstring = "insert into ....."
sqlcmd = New OleDbCommand(sqlstring, sqlcon)
End Sub
上面的连接字符串怎么样用数据源的方法写?我的意思是就像配置数据源一样,vs自动生成数据库连接字符串和sql操作语句,类似这样:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT DISTINCT [pbrand] FROM [produce] WHERE ([cclass] = ?)">
<SelectParameters>
<asp:ControlParameter ControlID="Label12" Name="cclass" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
谢谢·~·
------解决方案--------------------代码:protected void Button1_Click(object sender, EventArgs e)
{
this.SqlDataSource1.Insert();
}